summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-26 07:58:33 (GMT)
committerGitHub <noreply@github.com>2023-07-26 07:58:33 (GMT)
commitd2355426d688eb9c84b3db15bbae21921858afbf (patch)
treec38ed21229fc1bca525bc9f1f30e339c8fe30102
parentef808517f499b25f9f847c813067f24d73af051f (diff)
downloadcpython-d2355426d688eb9c84b3db15bbae21921858afbf.zip
cpython-d2355426d688eb9c84b3db15bbae21921858afbf.tar.gz
cpython-d2355426d688eb9c84b3db15bbae21921858afbf.tar.bz2
[3.12] gh-106350: Tkinter: do not ignore return value of `mp_init()` (GH-106351) (GH-107258)
(cherry picked from commit b5ae7c498438657a6ba0bf4cc216b9c2c93a06c7) Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-03-03-46-20.gh-issue-106350.LLcTEe.rst2
-rw-r--r--Modules/_tkinter.c5
2 files changed, 5 insertions, 2 deletions
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 0000000..681d63a
--- /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 15f9c04..5abde84 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -876,8 +876,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();