Skip to content

Commit

Permalink
[3.11] GH-100342: check for allocation failure in AC *args parsing (G…
Browse files Browse the repository at this point in the history
…H-100343). (#100568)

(cherry picked from commit 7cf164a)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
  • Loading branch information
kumaraditya303 committed Dec 28, 2022
1 parent fba8c7c commit ebe4288
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Lib/test/clinic.test
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,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]));
}
Expand All @@ -3339,7 +3342,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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in Argument Clinic.
8 changes: 7 additions & 1 deletion Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,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
Expand Down

0 comments on commit ebe4288

Please sign in to comment.