Skip to content

Commit 584c90b

Browse files
federicovalensosrinivasreddy
authored andcommitted
pythongh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode (python#126118)
1 parent aaa2f94 commit 584c90b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,7 @@ PySys_ResetWarnOptions(void)
28542854
static int
28552855
_PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
28562856
{
2857+
assert(tstate != NULL);
28572858
PyObject *warnoptions = get_warnoptions(tstate);
28582859
if (warnoptions == NULL) {
28592860
return -1;
@@ -2869,11 +2870,11 @@ PyAPI_FUNC(void)
28692870
PySys_AddWarnOptionUnicode(PyObject *option)
28702871
{
28712872
PyThreadState *tstate = _PyThreadState_GET();
2873+
_Py_EnsureTstateNotNULL(tstate);
2874+
assert(!_PyErr_Occurred(tstate));
28722875
if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
28732876
/* No return value, therefore clear error state if possible */
2874-
if (tstate) {
2875-
_PyErr_Clear(tstate);
2876-
}
2877+
_PyErr_Clear(tstate);
28772878
}
28782879
}
28792880

0 commit comments

Comments
 (0)