]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-96678: Fix undefined behavior in ceval.c (#96708)
authorMark Shannon <mark@hotpy.org>
Sat, 10 Sep 2022 00:12:06 +0000 (01:12 +0100)
committerGitHub <noreply@github.com>
Sat, 10 Sep 2022 00:12:06 +0000 (01:12 +0100)
Misc/NEWS.d/next/Core and Builtins/2022-09-09-13-13-27.gh-issue-96678.vMxi9F.rst [new file with mode: 0644]
Python/ceval.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-09-13-13-27.gh-issue-96678.vMxi9F.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-09-13-13-27.gh-issue-96678.vMxi9F.rst
new file mode 100644 (file)
index 0000000..575b52b
--- /dev/null
@@ -0,0 +1 @@
+Fix case of undefined behavior in ceval.c
index 7d4543ea03d9a01e4e11b68eb0e30cbc8f0c38ea..20d0e1c50a5f0a6069acba91b68dc83b8a4046f7 100644 (file)
@@ -5532,7 +5532,13 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
     /* Pack other positional arguments into the *args argument */
     if (co->co_flags & CO_VARARGS) {
         PyObject *u = NULL;
-        u = _PyTuple_FromArraySteal(args + n, argcount - n);
+        if (argcount == n) {
+            u = Py_NewRef(&_Py_SINGLETON(tuple_empty));
+        }
+        else {
+            assert(args != NULL);
+            u = _PyTuple_FromArraySteal(args + n, argcount - n);
+        }
         if (u == NULL) {
             goto fail_post_positional;
         }