Skip to content

Commit

Permalink
enable main() function execution in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
aarora79 committed Jan 1, 2025
1 parent e86da8d commit e5ac66f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion USACOBench/evaluation/judges/usaco_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ def unsafe_execute():
check_program = prefix_program + program + suffix_program

try:
exec_globals = {}
# Since we are executing untrusted code we want to remove all global
# variables from the namespace we provide to "exec" for running this code, but
# we do want to set the {'__name__': '__main__'} so that "main" function
# in the generated code does get called (while all the global variables from
# the original context are still cleared out),
# We should consider replacing exec with subprocess so that the code
# is run in a separate Python interpreter process.
exec_globals = {'__name__': '__main__'}
with swallow_io():
with time_limit(timeout):
# WARNING
Expand Down

0 comments on commit e5ac66f

Please sign in to comment.