Skip to content

Commit 0468ea1

Browse files
[3.13] gh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode (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]>
1 parent 9a59a51 commit 0468ea1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a possible ``NULL`` pointer dereference in :c:func:`!PySys_AddWarnOptionUnicode`.

Python/sysmodule.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,7 @@ PySys_ResetWarnOptions(void)
28412841
static int
28422842
_PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
28432843
{
2844+
assert(tstate != NULL);
28442845
PyObject *warnoptions = get_warnoptions(tstate);
28452846
if (warnoptions == NULL) {
28462847
return -1;
@@ -2856,11 +2857,11 @@ PyAPI_FUNC(void)
28562857
PySys_AddWarnOptionUnicode(PyObject *option)
28572858
{
28582859
PyThreadState *tstate = _PyThreadState_GET();
2860+
_Py_EnsureTstateNotNULL(tstate);
2861+
assert(!_PyErr_Occurred(tstate));
28592862
if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
28602863
/* No return value, therefore clear error state if possible */
2861-
if (tstate) {
2862-
_PyErr_Clear(tstate);
2863-
}
2864+
_PyErr_Clear(tstate);
28642865
}
28652866
}
28662867

0 commit comments

Comments
 (0)