From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:33:40 +0000 (+0530) Subject: Fix possible NULL pointer dereference in _PyThread_CurrentFrames (GH-96584) X-Git-Tag: v3.12.0a1~439 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=88a7f661ca02c0eb76b8f19234b8293b70f171e2;p=thirdparty%2FPython%2Fcpython.git Fix possible NULL pointer dereference in _PyThread_CurrentFrames (GH-96584) --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-05-15-07-25.gh-issue-96582.HEsL5s.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-05-15-07-25.gh-issue-96582.HEsL5s.rst new file mode 100644 index 000000000000..162f7baadf49 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-05-15-07-25.gh-issue-96582.HEsL5s.rst @@ -0,0 +1 @@ +Fix possible ``NULL`` pointer dereference in ``_PyThread_CurrentFrames``. Patch by Kumar Aditya. diff --git a/Python/pystate.c b/Python/pystate.c index 1c96f4f75f29..a0d61d7ebb3b 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1413,7 +1413,12 @@ _PyThread_CurrentFrames(void) if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_PyFrame_GetFrameObject(frame)); + PyObject *frameobj = (PyObject *)_PyFrame_GetFrameObject(frame); + if (frameobj == NULL) { + Py_DECREF(id); + goto fail; + } + int stat = PyDict_SetItem(result, id, frameobj); Py_DECREF(id); if (stat < 0) { goto fail;