Skip to content

Commit a6cbc9a

Browse files
giomascestefano-maggiolo
authored andcommitted
Test for a security bug.
1 parent d2a80c4 commit a6cbc9a

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

cmstestsuite/Tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,11 @@
223223
languages=(LANG_C),
224224
checks=[CheckOverallScore(100, 100)]),
225225

226+
# Rewrite input in the solution.
227+
228+
Test('rewrite-input',
229+
task=batch_fileio_managed, filename='rewrite-input.%l',
230+
languages=(LANG_C,),
231+
checks=[CheckOverallScore(0, 100)]),
232+
226233
]

cmstestsuite/code/rewrite-input.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
/*
4+
* This returns the wrong result, but overwrites the input file so
5+
* that a wrong result appears as a correct one. CMS is expected not
6+
* to be fooled by this cheat attempt.
7+
*
8+
* CMS can counter this attack by making input.txt not writable or by
9+
* rewriting it again before calling the checker. Both things should
10+
* happen at the moment. This test is here to check that at least one
11+
* is functional.
12+
*/
13+
14+
int userfunc(int x) {
15+
FILE *fin = fopen("input.txt", "w");
16+
fprintf(fin, "%d\n", x+1);
17+
fclose(fin);
18+
return x+1;
19+
}

0 commit comments

Comments
 (0)