Skip to content

Commit df2cdcf

Browse files
[3.12] Fix error handling in _PySys_UpdateConfig() (GH-109524) (#109550)
Fix error handling in _PySys_UpdateConfig() (GH-109524) (cherry picked from commit c829975) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent e5c860f commit df2cdcf

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
@@ -3466,7 +3466,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
34663466
if (config->pycache_prefix != NULL) {
34673467
SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);
34683468
} else {
3469-
PyDict_SetItemString(sysdict, "pycache_prefix", Py_None);
3469+
if (PyDict_SetItemString(sysdict, "pycache_prefix", Py_None) < 0) {
3470+
return -1;
3471+
}
34703472
}
34713473

34723474
COPY_LIST("argv", config->argv);
@@ -3480,7 +3482,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
34803482
SET_SYS_FROM_WSTR("_stdlib_dir", stdlibdir);
34813483
}
34823484
else {
3483-
PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None);
3485+
if (PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None) < 0) {
3486+
return -1;
3487+
}
34843488
}
34853489

34863490
#undef SET_SYS_FROM_WSTR
@@ -3490,6 +3494,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
34903494
// sys.flags
34913495
PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref
34923496
if (flags == NULL) {
3497+
if (!_PyErr_Occurred(tstate)) {
3498+
_PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.flags");
3499+
}
34933500
return -1;
34943501
}
34953502
if (set_flags_from_config(interp, flags) < 0) {

0 commit comments

Comments
 (0)