From f70fa5408a9e96dd4f4b5a994e87e149d5639d8b Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 19 Dec 2022 10:05:12 +0000 Subject: [PATCH 1/4] add null test --- Modules/clinic/_testclinic.c.h | 8 +++++++- Tools/clinic/clinic.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 21bde529470294..831f58ca650aab 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -2409,6 +2409,9 @@ vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } a = args[0]; __clinic_args = PyTuple_New(nargs - 1); + if (!__clinic_args) { + goto exit; + } for (Py_ssize_t i = 0; i < nargs - 1; ++i) { PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i])); } @@ -2769,6 +2772,9 @@ gh_99233_refcount(PyObject *module, PyObject *const *args, Py_ssize_t nargs) goto exit; } __clinic_args = PyTuple_New(nargs - 0); + if (!__clinic_args) { + goto exit; + } for (Py_ssize_t i = 0; i < nargs - 0; ++i) { PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i])); } @@ -2811,4 +2817,4 @@ gh_99240_double_free(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=9a5ca5909c087102 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e8211606b03d733a input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index fdf8041e14bbc1..5f5cfce163e668 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -962,12 +962,16 @@ def parser_body(prototype, *fields, declarations=''): if not new_or_init: parser_code.append(normalize_snippet(""" %s = PyTuple_New(%s); + if (!%s) {{ + goto exit; + }} for (Py_ssize_t i = 0; i < %s; ++i) {{ PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i])); }} """ % ( p.converter.parser_name, left_args, + p.converter.parser_name, left_args, p.converter.parser_name, max_pos From 1115035b302c5665ca2a7f2298a2e249ad3be19f Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 19 Dec 2022 10:08:54 +0000 Subject: [PATCH 2/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 --- .../Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst b/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst new file mode 100644 index 00000000000000..45badbb2cbc3d4 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst @@ -0,0 +1 @@ +Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in argument clinic. From 9e54462e9aed218a34edb8075b0faacf10c4f5ea Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 19 Dec 2022 10:39:49 +0000 Subject: [PATCH 3/4] clinic regen --- Lib/test/clinic.test | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/clinic.test b/Lib/test/clinic.test index 0d844234d9d1f6..53e5df5ba872ed 100644 --- a/Lib/test/clinic.test +++ b/Lib/test/clinic.test @@ -3781,6 +3781,9 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg } a = args[0]; __clinic_args = PyTuple_New(nargs - 1); + if (!__clinic_args) { + goto exit; + } for (Py_ssize_t i = 0; i < nargs - 1; ++i) { PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i])); } @@ -3793,7 +3796,7 @@ exit: static PyObject * test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args) -/*[clinic end generated code: output=081a953b8cbe7617 input=08dc2bf7afbf1613]*/ +/*[clinic end generated code: output=79b75dc07decc8d6 input=08dc2bf7afbf1613]*/ /*[clinic input] test_vararg From 1809dc6670213c66dc1ba58b6086ec70db435532 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 28 Dec 2022 02:13:16 +0100 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst --- .../Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst b/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst index 45badbb2cbc3d4..28f7363375267e 100644 --- a/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst +++ b/Misc/NEWS.d/next/Tools-Demos/2022-12-19-10-08-53.gh-issue-100342.qDFlQG.rst @@ -1 +1 @@ -Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in argument clinic. +Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in Argument Clinic.