Skip to content

Commit

Permalink
[3.13] gh-126108: Fix potential null pointer dereference in `PySys_Ad…
Browse files Browse the repository at this point in the history
…dWarnOptionUnicode` (GH-126118) (#129520)

gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (GH-126118)
(cherry picked from commit fad36bf)

Co-authored-by: Valery Fedorenko <[email protected]>
  • Loading branch information
miss-islington and federicovalenso authored Jan 31, 2025
1 parent 9a59a51 commit 0468ea1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a possible ``NULL`` pointer dereference in :c:func:`!PySys_AddWarnOptionUnicode`.
7 changes: 4 additions & 3 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 0468ea1

Please sign in to comment.