mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
[3.11] GH-100342: check for allocation failure in AC *args
parsing (GH-100343). (#100568)
(cherry picked from commit 7cf164ad5e
)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
fba8c7cf74
commit
ebe428824d
4 changed files with 16 additions and 2 deletions
|
@ -3327,6 +3327,9 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg
|
||||||
}
|
}
|
||||||
a = args[0];
|
a = args[0];
|
||||||
__clinic_args = PyTuple_New(nargs - 1);
|
__clinic_args = PyTuple_New(nargs - 1);
|
||||||
|
if (!__clinic_args) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
|
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
|
||||||
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
|
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
|
||||||
}
|
}
|
||||||
|
@ -3339,7 +3342,7 @@ exit:
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
|
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]
|
/*[clinic input]
|
||||||
test_vararg
|
test_vararg
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in Argument Clinic.
|
8
Modules/clinic/_testclinic.c.h
generated
8
Modules/clinic/_testclinic.c.h
generated
|
@ -2012,6 +2012,9 @@ vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
}
|
}
|
||||||
a = args[0];
|
a = args[0];
|
||||||
__clinic_args = PyTuple_New(nargs - 1);
|
__clinic_args = PyTuple_New(nargs - 1);
|
||||||
|
if (!__clinic_args) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
|
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
|
||||||
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
|
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
|
||||||
}
|
}
|
||||||
|
@ -2257,6 +2260,9 @@ gh_99233_refcount(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
__clinic_args = PyTuple_New(nargs - 0);
|
__clinic_args = PyTuple_New(nargs - 0);
|
||||||
|
if (!__clinic_args) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
|
for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
|
||||||
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
|
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
|
||||||
}
|
}
|
||||||
|
@ -2299,4 +2305,4 @@ gh_99240_double_free(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=fe398ac790310bc4 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=6b719efc1b8bd2c8 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -903,12 +903,16 @@ class CLanguage(Language):
|
||||||
if not new_or_init:
|
if not new_or_init:
|
||||||
parser_code.append(normalize_snippet("""
|
parser_code.append(normalize_snippet("""
|
||||||
%s = PyTuple_New(%s);
|
%s = PyTuple_New(%s);
|
||||||
|
if (!%s) {{
|
||||||
|
goto exit;
|
||||||
|
}}
|
||||||
for (Py_ssize_t i = 0; i < %s; ++i) {{
|
for (Py_ssize_t i = 0; i < %s; ++i) {{
|
||||||
PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i]));
|
PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i]));
|
||||||
}}
|
}}
|
||||||
""" % (
|
""" % (
|
||||||
p.converter.parser_name,
|
p.converter.parser_name,
|
||||||
left_args,
|
left_args,
|
||||||
|
p.converter.parser_name,
|
||||||
left_args,
|
left_args,
|
||||||
p.converter.parser_name,
|
p.converter.parser_name,
|
||||||
max_pos
|
max_pos
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue