8000 [3.12] gh-126108: Fix potential null pointer dereference in `PySys_Ad… · python/cpython@40d7f74 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 40d7f74

Browse files
[3.12] gh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode (GH-126118) (#129522)
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (GH-126118) (cherry picked from commit fad36bf) Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
1 parent 48f08fe commit 40d7f74

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
@@ -2653,6 +2653,7 @@ PySys_ResetWarnOptions(void)
26532653
static int
26542654
_PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
26552655
{
2656+
assert(tstate != NULL);
26562657
PyObject *warnoptions = get_warnoptions(tstate);
26572658
if (warnoptions == NULL) {
26582659
return -1;
@@ -2667,11 +2668,11 @@ void
26672668
PySys_AddWarnOptionUnicode(PyObject *option)
26682669
{
26692670
PyThreadState *tstate = _PyThreadState_GET();
2671+
_Py_EnsureTstateNotNULL(tstate);
2672+
assert(!_PyErr_Occurred(tstate));
26702673
if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
26712674
/* No return value, therefore clear error state if possible */
2672-
if (tstate) {
2673-
_PyErr_Clear(tstate);
2674-
}
2675+
_PyErr_Clear(tstate);
26752676
}
26762677
}
26772678

0 commit comments

Comments
 (0)
0