From cd374dd4c184348f7b46bbeb8ffb03ae8ba5bac4 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sun, 18 Sep 2022 15:44:19 +0800 Subject: [PATCH 1/4] gh-96821: Assert for demonstrating undefined behaviour --- Modules/_testcapimodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 2d4c73cfe97097..de8b048f6efa26 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4918,6 +4918,7 @@ meth_fastcall_keywords(PyObject* self, PyObject* const* args, if (pyargs == NULL) { return NULL; } + assert(args != NULL); PyObject *pykwargs = PyObject_Vectorcall((PyObject*)&PyDict_Type, args + nargs, 0, kwargs); return Py_BuildValue("NNN", _null_to_none(self), pyargs, pykwargs); From 5f888861bdc1fd22b5711326ea39b28e4cb5cfd1 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sun, 18 Sep 2022 16:41:59 +0800 Subject: [PATCH 2/4] Fix UB --- Modules/_testcapimodule.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index de8b048f6efa26..b8f71d47ed524f 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4918,9 +4918,10 @@ meth_fastcall_keywords(PyObject* self, PyObject* const* args, if (pyargs == NULL) { return NULL; } - assert(args != 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); } From 01d749018f53dc281dcd69a663e7b6dfca855ca1 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 18 Sep 2022 08:47:41 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst 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 00000000000000..14ec255c009b68 --- /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`. From 1810e7be12c82807e55de90ae9af7006f32afa76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Mon, 19 Sep 2022 07:42:43 +0800 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst Co-authored-by: C.A.M. Gerlach --- .../2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 14ec255c009b68..4fd0532e827d18 100644 --- 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 @@ -1 +1 @@ -Fix undefined behaviour in `_testcapimodule.c`. +Fix undefined behaviour in ``_testcapimodule.c``.