]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnico...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 31 Jan 2025 15:02:44 +0000 (16:02 +0100)
committerGitHub <noreply@github.com>
Fri, 31 Jan 2025 15:02:44 +0000 (20:32 +0530)
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (GH-126118)
(cherry picked from commit fad36bf38248130bc48b81a5e7c31a7649a6456e)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
Misc/NEWS.d/next/Security/2024-10-29-09-15-10.gh-issue-126108.eTIjHY.rst [new file with mode: 0644]
Python/sysmodule.c

diff --git a/Misc/NEWS.d/next/Security/2024-10-29-09-15-10.gh-issue-126108.eTIjHY.rst b/Misc/NEWS.d/next/Security/2024-10-29-09-15-10.gh-issue-126108.eTIjHY.rst
new file mode 100644 (file)
index 0000000..9f2c7e8
--- /dev/null
@@ -0,0 +1 @@
+Fix a possible ``NULL`` pointer dereference in :c:func:`!PySys_AddWarnOptionUnicode`.
index 3f170fff156fcd7fe53d9577cdf1341f6f147fc6..9cf4a580d4408f385fa2b27e161a8a4b8a34ce1a 100644 (file)
@@ -2841,6 +2841,7 @@ PySys_ResetWarnOptions(void)
 static int
 _PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
 {
+    assert(tstate != NULL);
     PyObject *warnoptions = get_warnoptions(tstate);
     if (warnoptions == NULL) {
         return -1;
@@ -2856,11 +2857,11 @@ PyAPI_FUNC(void)
 PySys_AddWarnOptionUnicode(PyObject *option)
 {
     PyThreadState *tstate = _PyThreadState_GET();
+    _Py_EnsureTstateNotNULL(tstate);
+    assert(!_PyErr_Occurred(tstate));
     if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
         /* No return value, therefore clear error state if possible */
-        if (tstate) {
-            _PyErr_Clear(tstate);
-        }
+        _PyErr_Clear(tstate);
     }
 }