From 6122591ca89bb2972918dae1a6f1b5c36d049a5d Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Tue, 25 Jul 2023 13:52:07 -0500 Subject: [PATCH] gh-106350: Tkinter: do not ignore return value of `mp_init()` (GH-106351) (cherry picked from commit b5ae7c498438657a6ba0bf4cc216b9c2c93a06c7) Co-authored-by: Christopher Chavez --- .../Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst | 2 ++ Modules/_tkinter.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst diff --git a/Misc/NEWS.d/next/Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst b/Misc/NEWS.d/next/Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst new file mode 100644 index 00000000000000..681d63a6668be8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst @@ -0,0 +1,2 @@ +Detect possible memory allocation failure in the libtommath function :c:func:`mp_init` +used by the ``_tkinter`` module. diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 2aab68ee1784f9..e5377073ff765e 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -906,8 +906,9 @@ asBignumObj(PyObject *value) return NULL; } hexchars += neg + 2; /* skip sign and "0x" */ - mp_init(&bigValue); - if (mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) { + if (mp_init(&bigValue) != MP_OKAY || + mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) + { mp_clear(&bigValue); Py_DECREF(hexstr); PyErr_NoMemory();