diff options
author | colorfulappl <colorfulappl@qq.com> | 2022-12-17 06:37:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-17 06:37:44 (GMT) |
commit | efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4 (patch) | |
tree | e33a76ccf9dfad64e82d08d073d86706152758b2 /Modules/_testcapi | |
parent | 9cdd2fa63b7549d00830bccf19a34e9d69d0b15e (diff) | |
download | cpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.zip cpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.tar.gz cpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.tar.bz2 |
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (#99890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r-- | Modules/_testcapi/getargs.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Modules/_testcapi/getargs.c b/Modules/_testcapi/getargs.c index 25a8e5f..aa20131 100644 --- a/Modules/_testcapi/getargs.c +++ b/Modules/_testcapi/getargs.c @@ -854,6 +854,24 @@ getargs_s_hash_int2(PyObject *self, PyObject *args, PyObject *kwargs) Py_RETURN_NONE; } +static PyObject * +gh_99240_clear_args(PyObject *self, PyObject *args) +{ + char *a = NULL; + char *b = NULL; + + if (!PyArg_ParseTuple(args, "eses", "idna", &a, "idna", &b)) { + if (a || b) { + PyErr_Clear(); + PyErr_SetString(PyExc_AssertionError, "Arguments are not cleared."); + } + return NULL; + } + PyMem_Free(a); + PyMem_Free(b); + Py_RETURN_NONE; +} + static PyMethodDef test_methods[] = { {"get_args", get_args, METH_VARARGS}, {"get_kwargs", _PyCFunction_CAST(get_kwargs), METH_VARARGS|METH_KEYWORDS}, @@ -906,6 +924,7 @@ static PyMethodDef test_methods[] = { {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, {"test_k_code", test_k_code, METH_NOARGS}, {"test_s_code", test_s_code, METH_NOARGS}, + {"gh_99240_clear_args", gh_99240_clear_args, METH_VARARGS}, {NULL}, }; |