mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
[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 fad36bf382
)
Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
This commit is contained in:
parent
9a59a51733
commit
0468ea1230
2 changed files with 5 additions and 3 deletions
|
@ -0,0 +1 @@
|
||||||
|
Fix a possible ``NULL`` pointer dereference in :c:func:`!PySys_AddWarnOptionUnicode`.
|
|
@ -2841,6 +2841,7 @@ PySys_ResetWarnOptions(void)
|
||||||
static int
|
static int
|
||||||
_PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
|
_PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option)
|
||||||
{
|
{
|
||||||
|
assert(tstate != NULL);
|
||||||
PyObject *warnoptions = get_warnoptions(tstate);
|
PyObject *warnoptions = get_warnoptions(tstate);
|
||||||
if (warnoptions == NULL) {
|
if (warnoptions == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2856,11 +2857,11 @@ PyAPI_FUNC(void)
|
||||||
PySys_AddWarnOptionUnicode(PyObject *option)
|
PySys_AddWarnOptionUnicode(PyObject *option)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
_Py_EnsureTstateNotNULL(tstate);
|
||||||
|
assert(!_PyErr_Occurred(tstate));
|
||||||
if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
|
if (_PySys_AddWarnOptionWithError(tstate, option) < 0) {
|
||||||
/* No return value, therefore clear error state if possible */
|
/* No return value, therefore clear error state if possible */
|
||||||
if (tstate) {
|
_PyErr_Clear(tstate);
|
||||||
_PyErr_Clear(tstate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue