From 9e8e018673b922bafa599ec7c74ee44ed3603a7c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 18 Sep 2023 20:09:59 +0300 Subject: [PATCH] Fix error handling in _PySys_UpdateConfig() (GH-109524) (cherry picked from commit c829975428253568d47ebfc3104fa7386b5e0b58) Co-authored-by: Serhiy Storchaka --- Python/sysmodule.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 6e9ec90c9d1c3e..d0941e8cfebeb6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3113,7 +3113,9 @@ _PySys_UpdateConfig(PyThreadState *tstate) if (config->pycache_prefix != NULL) { SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix); } else { - PyDict_SetItemString(sysdict, "pycache_prefix", Py_None); + if (PyDict_SetItemString(sysdict, "pycache_prefix", Py_None) < 0) { + return -1; + } } COPY_LIST("argv", config->argv); @@ -3127,7 +3129,9 @@ _PySys_UpdateConfig(PyThreadState *tstate) SET_SYS_FROM_WSTR("_stdlib_dir", stdlibdir); } else { - PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None); + if (PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None) < 0) { + return -1; + } } #undef SET_SYS_FROM_WSTR @@ -3137,6 +3141,9 @@ _PySys_UpdateConfig(PyThreadState *tstate) // sys.flags PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref if (flags == NULL) { + if (!_PyErr_Occurred(tstate)) { + _PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.flags"); + } return -1; } if (set_flags_from_config(interp, flags) < 0) {