Skip to content

Commit 17a335d

Browse files
[3.11] Fix error handling in _PySys_UpdateConfig() (GH-109524) (GH-109551)
(cherry picked from commit c829975) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 2184b76 commit 17a335d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Python/sysmodule.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
31133113
if (config->pycache_prefix != NULL) {
31143114
SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);
31153115
} else {
3116-
PyDict_SetItemString(sysdict, "pycache_prefix", Py_None);
3116+
if (PyDict_SetItemString(sysdict, "pycache_prefix", Py_None) < 0) {
3117+
return -1;
3118+
}
31173119
}
31183120

31193121
COPY_LIST("argv", config->argv);
@@ -3127,7 +3129,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
31273129
SET_SYS_FROM_WSTR("_stdlib_dir", stdlibdir);
31283130
}
31293131
else {
3130-
PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None);
3132+
if (PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None) < 0) {
3133+
return -1;
3134+
}
31313135
}
31323136

31333137
#undef SET_SYS_FROM_WSTR
@@ -3137,6 +3141,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
31373141
// sys.flags
31383142
PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref
31393143
if (flags == NULL) {
3144+
if (!_PyErr_Occurred(tstate)) {
3145+
_PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.flags");
3146+
}
31403147
return -1;
31413148
}
31423149
if (set_flags_from_config(interp, flags) < 0) {

0 commit comments

Comments
 (0)