Skip to content

Commit 485f264

Browse files
RiolkuXyene
authored andcommitted
executors: modify shell_executor to work with new handlers
This seems to be the only extra handler.
1 parent 03360da commit 485f264

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

dmoj/executors/shell_executor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import shutil
3-
import sys
43

4+
from dmoj.cptbox.isolate import DeniedSyscall, protection_fault
55
from dmoj.executors.script_executor import ScriptExecutor
66

77

@@ -27,12 +27,11 @@ def get_security(self, launch_kwargs=None):
2727
sec = super().get_security(launch_kwargs)
2828
allowed = set(self.get_allowed_exec())
2929

30-
def handle_execve(debugger):
31-
path = sec.get_full_path(debugger, debugger.readstr(debugger.uarg0))
32-
if path in allowed:
33-
return True
34-
print('Not allowed to use command:', path, file=sys.stderr)
35-
return False
30+
def handle_execve(debugger) -> None:
31+
path = sec.get_full_path_unnormalized(debugger, debugger.readstr(debugger.uarg0))
32+
path = '/' + os.path.normpath(path).lstrip('/')
33+
if path not in allowed:
34+
raise DeniedSyscall(protection_fault, f'Not allowed to use command: {path}')
3635

3736
sec[sys_execve] = handle_execve
3837
sec[sys_eaccess] = sec[sys_access]

0 commit comments

Comments
 (0)