]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127165: Disallow embedded NULL characters in `_interpreters` (GH-127199...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 1 Dec 2024 06:55:55 +0000 (07:55 +0100)
committerGitHub <noreply@github.com>
Sun, 1 Dec 2024 06:55:55 +0000 (06:55 +0000)
gh-127165: Disallow embedded NULL characters in `_interpreters` (GH-127199)
(cherry picked from commit 46bfd26fb294a8769ef6d0c056ee6c9df022a037)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Lib/test/test_interpreters/test_api.py
Python/crossinterp.c

index 42819ae9b180b46beabab9b3502c8943272ee141..61beb317c379751c0925a8590c3c39d25ff0dcb5 100644 (file)
@@ -1650,6 +1650,10 @@ class LowLevelTests(TestBase):
             self.assertIs(after2, None)
             self.assertEqual(after3.type.__name__, 'AssertionError')
 
+            with self.assertRaises(ValueError):
+                # GH-127165: Embedded NULL characters broke the lookup
+                _interpreters.set___main___attrs(interpid, {"\x00": 1})
+
         with self.subTest('from C-API'):
             with self.interpreter_from_capi() as interpid:
                 with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
index 01bb45d23bac1bb4f6f96cc644d5371c52185c13..ac379a1ad0fb6d0a7fd710d02661a50915e75f91 100644 (file)
@@ -346,6 +346,11 @@ _copy_string_obj_raw(PyObject *strobj, Py_ssize_t *p_size)
         return NULL;
     }
 
+    if (size != (Py_ssize_t)strlen(str)) {
+        PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
+        return NULL;
+    }
+
     char *copied = PyMem_RawMalloc(size+1);
     if (copied == NULL) {
         PyErr_NoMemory();