Skip to content

Commit 71db083

Browse files
giomascestefano-maggiolo
authored andcommitted
Fix untrusted input bug.
During the execution of a task of Batch type, the contestant program could tamper with the input file (usually input.txt). We check it out again from the database to be sure. Committer note: this patch was first written when the contestant could actually write the input file. At commit time, this is no longer true (it can only write the output file). Nonetheless, graders might decide to delete the input, so the patch still makes sense.
1 parent 1fff330 commit 71db083

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

cms/grading/tasktypes/Batch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,21 @@ def evaluate(self, job, file_cacher):
331331
manager_filename,
332332
job.managers[manager_filename].digest,
333333
executable=True)
334+
# Rewrite input file. The untrusted
335+
# contestant program should not be able to
336+
# modify it; however, the grader may
337+
# destroy the input file to prevent the
338+
# contestant's program from directly
339+
# accessing it. Since we cannot create
340+
# files already existing in the sandbox,
341+
# we try removing the file first.
342+
try:
343+
sandbox.remove_file(input_filename)
344+
except OSError as e:
345+
pass
346+
sandbox.create_file_from_storage(
347+
input_filename,
348+
job.input)
334349
success, _ = evaluation_step(
335350
sandbox,
336351
[["./%s" % manager_filename,

0 commit comments

Comments
 (0)