]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode...
authorValery Fedorenko <federicovalenso@gmail.com>
Fri, 31 Jan 2025 14:36:30 +0000 (22:36 +0800)
committerGitHub <noreply@github.com>
Fri, 31 Jan 2025 14:36:30 +0000 (20:06 +0530)
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 7e4cb45af05672f37444cb3cef180f4254f77212..11b96c8455de14cfae8400298b17dc44330d9895 100644 (file)
@@ -2847,6 +2847,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;
@@ -2862,11 +2863,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);
     }
 }