Skip to content

Commit 46f18c8

Browse files
authored
Merge pull request #4 from aarora79/main
enable main() function execution in generated code
2 parents e86da8d + e5ac66f commit 46f18c8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

USACOBench/evaluation/judges/usaco_utils.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ def unsafe_execute():
107107
check_program = prefix_program + program + suffix_program
108108

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

0 commit comments

Comments
 (0)