Skip to content

Commit ebe4288

Browse files
[3.11] GH-100342: check for allocation failure in AC *args parsing (GH-100343). (#100568)
(cherry picked from commit 7cf164a) Co-authored-by: Kumar Aditya <[email protected]>
1 parent fba8c7c commit ebe4288

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Lib/test/clinic.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3327,6 +3327,9 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg
33273327
}
33283328
a = args[0];
33293329
__clinic_args = PyTuple_New(nargs - 1);
3330+
if (!__clinic_args) {
3331+
goto exit;
3332+
}
33303333
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
33313334
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
33323335
}
@@ -3339,7 +3342,7 @@ exit:
33393342

33403343
static PyObject *
33413344
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
3342-
/*[clinic end generated code: output=081a953b8cbe7617 input=08dc2bf7afbf1613]*/
3345+
/*[clinic end generated code: output=79b75dc07decc8d6 input=08dc2bf7afbf1613]*/
33433346

33443347
/*[clinic input]
33453348
test_vararg
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in Argument Clinic.

Modules/clinic/_testclinic.c.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/clinic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,16 @@ def parser_body(prototype, *fields, declarations=''):
903903
if not new_or_init:
904904
parser_code.append(normalize_snippet("""
905905
%s = PyTuple_New(%s);
906+
if (!%s) {{
907+
goto exit;
908+
}}
906909
for (Py_ssize_t i = 0; i < %s; ++i) {{
907910
PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i]));
908911
}}
909912
""" % (
910913
p.converter.parser_name,
911914
left_args,
915+
p.converter.parser_name,
912916
left_args,
913917
p.converter.parser_name,
914918
max_pos

0 commit comments

Comments
 (0)