diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-11 20:02:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 20:02:49 (GMT) |
commit | 41cddc2e93a285b81fa30ac542b088bd9d0112e9 (patch) | |
tree | 327402188686f3424f35bfdee06895ef661e1095 /Python | |
parent | e8998e46a7ce8ad336e0941a6da6e50cb88d1e47 (diff) | |
download | cpython-41cddc2e93a285b81fa30ac542b088bd9d0112e9.zip cpython-41cddc2e93a285b81fa30ac542b088bd9d0112e9.tar.gz cpython-41cddc2e93a285b81fa30ac542b088bd9d0112e9.tar.bz2 |
gh-105375: Improve error handling in the sys extension module (#105611)
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 7027410..90e5e65 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2721,14 +2721,20 @@ _PySys_AddXOptionWithError(const wchar_t *s) const wchar_t *name_end = wcschr(s, L'='); if (!name_end) { name = PyUnicode_FromWideChar(s, -1); + if (name == NULL) { + goto error; + } value = Py_NewRef(Py_True); } else { name = PyUnicode_FromWideChar(s, name_end - s); + if (name == NULL) { + goto error; + } value = PyUnicode_FromWideChar(name_end + 1, -1); - } - if (name == NULL || value == NULL) { - goto error; + if (value == NULL) { + goto error; + } } if (PyDict_SetItem(opts, name, value) < 0) { goto error; @@ -3374,14 +3380,20 @@ sys_add_xoption(PyObject *opts, const wchar_t *s) const wchar_t *name_end = wcschr(s, L'='); if (!name_end) { name = PyUnicode_FromWideChar(s, -1); + if (name == NULL) { + goto error; + } value = Py_NewRef(Py_True); } else { name = PyUnicode_FromWideChar(s, name_end - s); + if (name == NULL) { + goto error; + } value = PyUnicode_FromWideChar(name_end + 1, -1); - } - if (name == NULL || value == NULL) { - goto error; + if (value == NULL) { + goto error; + } } if (PyDict_SetItem(opts, name, value) < 0) { goto error; |