]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96821: Fix undefined behaviour in `_testcapimodule.c` (GH-96915)
authorMatthias Görgens <matthias.goergens@gmail.com>
Mon, 19 Sep 2022 07:59:13 +0000 (15:59 +0800)
committerGitHub <noreply@github.com>
Mon, 19 Sep 2022 07:59:13 +0000 (15:59 +0800)
* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
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 2d4c73cfe97097bb13f0c7007216a0feb6824ca3..b8f71d47ed524f1c6fa4c44e01f1dfa39133c763 100644 (file)
@@ -4918,8 +4918,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);
 }