Skip to content

Commit

Permalink
Check for symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
jordi-petit committed Apr 16, 2024
1 parent c9b3a0e commit ec7b2d3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion std/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from jutge import util
import monitor

class CheatingException(Exception):
pass


class Judge:

def go(self):
Expand Down Expand Up @@ -367,14 +371,18 @@ def execution_one_test(self, exe, test):
else:
success = True

# Move the files up
# Move the files up (and check they are not simlinks)
for ext in ('inp', 'out', 'err', 'log', 'res'):
# the following check is due to a difficult bug we once had
if not util.file_exists(test + '.' + ext):
raise Exception('%s missing!!!' % (test + '.' + ext,))
else:
if os.path.islink(test + '.' + ext):
raise CheatingException('%s is a simlink!!!' % (test + '.' + ext,))
util.move_file(test + '.' + ext, '..')
if util.file_exists('exception.txt'):
if os.path.islink('exception.txt'):
raise CheatingException('%s is a simlink!!!' % ('exception.txt',))
util.del_file('../%s.exc' % test)
util.move_file('exception.txt', '../%s.exc' % test)

Expand Down Expand Up @@ -628,6 +636,14 @@ class Record:
judge.go()
# print json.dumps(judge, default=lambda obj: vars(obj), indent=4)
sys.exit(0)
except CheatingException as e:
util.write_file(d + '/correction/correction.yml', 'veredict: UE\nverdict_info: Cheating\n')
logging.info('!!!! exception caught !!!!')
logging.info(e)
print(e, file=sys.stderr)
traceback.print_exc(file=sys.stderr)
print(json.dumps(judge, default=lambda obj: vars(obj), indent=4), file=sys.stderr)
sys.exit(1)
except Exception as e:
util.write_file(d + '/correction/correction.yml', 'veredict: IE\ninternal_error: %s\n' % e)
logging.info('!!!! exception caught !!!!')
Expand Down

0 comments on commit ec7b2d3

Please sign in to comment.