Skip to content

Commit 7cf164a

Browse files
GH-100342: check for allocation failure in AC *args parsing (#100343)
1 parent e97afef commit 7cf164a

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
@@ -3781,6 +3781,9 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg
37813781
}
37823782
a = args[0];
37833783
__clinic_args = PyTuple_New(nargs - 1);
3784+
if (!__clinic_args) {
3785+
goto exit;
3786+
}
37843787
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
37853788
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
37863789
}
@@ -3793,7 +3796,7 @@ exit:
37933796

37943797
static PyObject *
37953798
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
3796-
/*[clinic end generated code: output=081a953b8cbe7617 input=08dc2bf7afbf1613]*/
3799+
/*[clinic end generated code: output=79b75dc07decc8d6 input=08dc2bf7afbf1613]*/
37973800

37983801
/*[clinic input]
37993802
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
@@ -960,12 +960,16 @@ def parser_body(prototype, *fields, declarations=''):
960960
if not new_or_init:
961961
parser_code.append(normalize_snippet("""
962962
%s = PyTuple_New(%s);
963+
if (!%s) {{
964+
goto exit;
965+
}}
963966
for (Py_ssize_t i = 0; i < %s; ++i) {{
964967
PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i]));
965968
}}
966969
""" % (
967970
p.converter.parser_name,
968971
left_args,
972+
p.converter.parser_name,
969973
left_args,
970974
p.converter.parser_name,
971975
max_pos

0 commit comments

Comments
 (0)