From 5b531e417302c096e022ceed74d14bf0cee92b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rafael=20Oses?= Date: Fri, 6 Jun 2025 20:54:32 -0400 Subject: [PATCH 1/3] fix: bad seccomp detection Improved bad seccomp detection --- dmoj/cptbox/tracer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dmoj/cptbox/tracer.py b/dmoj/cptbox/tracer.py index 53e63fb2d..aebf8c9e9 100644 --- a/dmoj/cptbox/tracer.py +++ b/dmoj/cptbox/tracer.py @@ -30,7 +30,7 @@ _SYSCALL_INDICIES[PTBOX_ABI_ARM64] = 5 FREEBSD = sys.platform.startswith('freebsd') -BAD_SECCOMP = sys.platform == 'linux' and tuple(map(int, os.uname().release.partition('-')[0].split('.'))) < (4, 8) +BAD_SECCOMP = is_bad_seccomp() _address_bits = { PTBOX_ABI_X86: 32, @@ -424,3 +424,17 @@ def unsafe_communicate(self, input: Optional[bytes] = None) -> Tuple[bytes, byte def can_debug(abi: int) -> bool: return abi in SUPPORTED_ABIS + +def is_bad_seccomp() -> bool: + try: + version_parts = os.uname().release.partition('-')[0].split('.') + clean_parts = [] + for part in version_parts: + clean_part = ''.join(c for c in part if c.isdigit()) + if clean_part: + clean_parts.append(int(clean_part)) + return sys.platform == 'linux' and tuple(clean_parts) < (4, 8) + except (ValueError, IndexError): + # Default to assuming bad seccomp if we can't parse + return True + From f91c053fc37b5af4c363faf47aa37d9e9d6878c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rafael=20Oses?= Date: Sun, 15 Jun 2025 00:13:49 -0400 Subject: [PATCH 2/3] Fixed is_bad_seccomp --- dmoj/cptbox/tracer.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/dmoj/cptbox/tracer.py b/dmoj/cptbox/tracer.py index aebf8c9e9..4babce8de 100644 --- a/dmoj/cptbox/tracer.py +++ b/dmoj/cptbox/tracer.py @@ -30,7 +30,6 @@ _SYSCALL_INDICIES[PTBOX_ABI_ARM64] = 5 FREEBSD = sys.platform.startswith('freebsd') -BAD_SECCOMP = is_bad_seccomp() _address_bits = { PTBOX_ABI_X86: 32, @@ -43,6 +42,20 @@ HandlerCallback = Callable[[Debugger], bool] +def is_bad_seccomp() -> bool: + try: + version_parts = os.uname().release.partition('-')[0].split('.') + clean_parts = [] + for part in version_parts: + clean_part = ''.join(c for c in part if c.isdigit()) + if clean_part: + clean_parts.append(int(clean_part)) + return sys.platform == 'linux' and tuple(clean_parts) < (4, 8) + except (ValueError, IndexError): + # Default to assuming bad seccomp if we can't parse + return True + +BAD_SECCOMP = is_bad_seccomp() class MaxLengthExceeded(ValueError): pass @@ -424,17 +437,3 @@ def unsafe_communicate(self, input: Optional[bytes] = None) -> Tuple[bytes, byte def can_debug(abi: int) -> bool: return abi in SUPPORTED_ABIS - -def is_bad_seccomp() -> bool: - try: - version_parts = os.uname().release.partition('-')[0].split('.') - clean_parts = [] - for part in version_parts: - clean_part = ''.join(c for c in part if c.isdigit()) - if clean_part: - clean_parts.append(int(clean_part)) - return sys.platform == 'linux' and tuple(clean_parts) < (4, 8) - except (ValueError, IndexError): - # Default to assuming bad seccomp if we can't parse - return True - From 7dc25a8b95f2a08ea0a80d2d3ead777a686eb66b Mon Sep 17 00:00:00 2001 From: AntennaeVY Date: Thu, 10 Jul 2025 09:34:58 -0400 Subject: [PATCH 3/3] fix formatting errors --- dmoj/cptbox/tracer.py | 3 +++ dmoj/executors/autoconfig.py | 8 +++++--- dmoj/tests/test_int_patch.py | 4 +--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dmoj/cptbox/tracer.py b/dmoj/cptbox/tracer.py index 4babce8de..b1c4847ce 100644 --- a/dmoj/cptbox/tracer.py +++ b/dmoj/cptbox/tracer.py @@ -42,6 +42,7 @@ HandlerCallback = Callable[[Debugger], bool] + def is_bad_seccomp() -> bool: try: version_parts = os.uname().release.partition('-')[0].split('.') @@ -55,8 +56,10 @@ def is_bad_seccomp() -> bool: # Default to assuming bad seccomp if we can't parse return True + BAD_SECCOMP = is_bad_seccomp() + class MaxLengthExceeded(ValueError): pass diff --git a/dmoj/executors/autoconfig.py b/dmoj/executors/autoconfig.py index f65db2b6f..f4435d9e4 100644 --- a/dmoj/executors/autoconfig.py +++ b/dmoj/executors/autoconfig.py @@ -60,9 +60,11 @@ def main(): else: if not args.silent: print_ansi( - f'#ansi[{feedback or "Success"}](green|bold)' - if success - else f'#ansi[{feedback or "Failed"}](red|bold)', + ( + f'#ansi[{feedback or "Success"}](green|bold)' + if success + else f'#ansi[{feedback or "Failed"}](red|bold)' + ), file=sys.stderr, ) diff --git a/dmoj/tests/test_int_patch.py b/dmoj/tests/test_int_patch.py index 38f01e97c..cd95f0b01 100644 --- a/dmoj/tests/test_int_patch.py +++ b/dmoj/tests/test_int_patch.py @@ -63,6 +63,4 @@ def test_parse_string_long(self): def test_parse_int(self): self.assertEqual(int(1), 1) self.assertEqual(int(-1337), -1337) - self.assertEqual( - int(10**builtin_int_patch.INT_MAX_NUMBER_DIGITS), 10**builtin_int_patch.INT_MAX_NUMBER_DIGITS - ) + self.assertEqual(int(10**builtin_int_patch.INT_MAX_NUMBER_DIGITS), 10**builtin_int_patch.INT_MAX_NUMBER_DIGITS)