]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96821: Fix undefined behaviour in `_testcapimodule.c` (GH-96915) (GH-96926)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 19 Sep 2022 10:20:23 +0000 (03:20 -0700)
committerGitHub <noreply@github.com>
Mon, 19 Sep 2022 10:20:23 +0000 (18:20 +0800)
* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

(cherry picked from commit cbdeda8ce7a3543cb3376d70e4cd46fcf24f42a7)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst [new file with mode: 0644]
Modules/_testcapimodule.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst
new file mode 100644 (file)
index 0000000..4fd0532
--- /dev/null
@@ -0,0 +1 @@
+Fix undefined behaviour in ``_testcapimodule.c``.
index 9f74c99769117206167d36ff658d0d905276a9f6..5c582dda4fbf9d218839261e4608023a95a02fbe 100644 (file)
@@ -5475,8 +5475,10 @@ meth_fastcall_keywords(PyObject* self, PyObject* const* args,
     if (pyargs == NULL) {
         return NULL;
     }
+    assert(args != NULL || nargs == 0);
+    PyObject* const* args_offset = args == NULL ? NULL : args + nargs;
     PyObject *pykwargs = PyObject_Vectorcall((PyObject*)&PyDict_Type,
-                                              args + nargs, 0, kwargs);
+                                              args_offset, 0, kwargs);
     return Py_BuildValue("NNN", _null_to_none(self), pyargs, pykwargs);
 }