[Python-checkins] gh-96821: Fix undefined behaviour in `_testcapimodule.c` (GH-96915)

Fidget-Spinner webhook-mailer at python.org
Mon Sep 19 03:59:59 EDT 2022


https://github.com/python/cpython/commit/cbdeda8ce7a3543cb3376d70e4cd46fcf24f42a7
commit: cbdeda8ce7a3543cb3376d70e4cd46fcf24f42a7
branch: main
author: Matthias Görgens <matthias.goergens at gmail.com>
committer: Fidget-Spinner <kenjin at python.org>
date: 2022-09-19T15:59:13+08:00
summary:

gh-96821: Fix undefined behaviour in `_testcapimodule.c` (GH-96915)

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach at Gerlach.CAM>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst
M 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
index 000000000000..4fd0532e827d
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst	
@@ -0,0 +1 @@
+Fix undefined behaviour in ``_testcapimodule.c``.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 2d4c73cfe970..b8f71d47ed52 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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);
 }
 



More information about the Python-checkins mailing list