Skip to content

Commit 1fff330

Browse files
giomascestefano-maggiolo
authored andcommitted
Another, more angry, test about tampering with the input.
1 parent a6cbc9a commit 1fff330

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

cmstestsuite/Tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,9 @@
230230
languages=(LANG_C,),
231231
checks=[CheckOverallScore(0, 100)]),
232232

233+
Test('delete-write-input',
234+
task=batch_fileio_managed, filename='delete-write-input.%l',
235+
languages=(LANG_C,),
236+
checks=[CheckOverallScore(0, 100)]),
237+
233238
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
4+
/*
5+
* This returns the wrong result, but deletes and writes again the
6+
* input file so that a wrong result appears as a correct one. CMS is
7+
* expected not to be fooled by this cheat attempt.
8+
*
9+
* CMS can counter this attack by rewriting the input file again
10+
* before calling the checker. This test is here to check that this is
11+
* done.
12+
*/
13+
14+
int userfunc(int x) {
15+
unlink("input.txt");
16+
FILE *fin = fopen("input.txt", "w");
17+
fprintf(fin, "%d\n", x+1);
18+
fclose(fin);
19+
return x+1;
20+
}

0 commit comments

Comments
 (0)