summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-01-31 15:02:44 (GMT)
committerGitHub <noreply@github.com>2025-01-31 15:02:44 (GMT)
commit0468ea12305ef5a0a3d1dc4af8a82fb94d202cd6 (patch)
treed8bd0676716f4745184c4dc2cb146377420dc3bf /Python/sysmodule.c
parent9a59a51733e58b6091ca9157fd43cc9d0f93a96f (diff)
downloadcpython-0468ea12305ef5a0a3d1dc4af8a82fb94d202cd6.zip
cpython-0468ea12305ef5a0a3d1dc4af8a82fb94d202cd6.tar.gz
cpython-0468ea12305ef5a0a3d1dc4af8a82fb94d202cd6.tar.bz2
[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 fad36bf38248130bc48b81a5e7c31a7649a6456e) Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 3f170ff..9cf4a58 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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;
@@ -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);
}
}