summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-09-19 10:20:23 (GMT)
committerGitHub <noreply@github.com>2022-09-19 10:20:23 (GMT)
commit88a3f1873ec4e6d35b1736c480c7087e01fca40f (patch)
treec067861046782e324a1611c27b859256f2d62785
parentf4be544a0317fba25fad1e8a13d7f9f2f58f177d (diff)
downloadcpython-88a3f1873ec4e6d35b1736c480c7087e01fca40f.zip
cpython-88a3f1873ec4e6d35b1736c480c7087e01fca40f.tar.gz
cpython-88a3f1873ec4e6d35b1736c480c7087e01fca40f.tar.bz2
gh-96821: Fix undefined behaviour in `_testcapimodule.c` (GH-96915) (GH-96926)
* 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>
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst1
-rw-r--r--Modules/_testcapimodule.c4
2 files changed, 4 insertions, 1 deletions
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 0000000..4fd0532
--- /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 9f74c99..5c582dd 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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);
}