diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-11 21:08:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 21:08:40 (GMT) |
commit | f98d475ee311268b28a9fc598a4efd22696d1208 (patch) | |
tree | 6e06f887e17395a6f6af9898394c072c85050521 /Python/sysmodule.c | |
parent | a03449374ebd5bffe54d3e09d36b54bc605551d8 (diff) | |
download | cpython-f98d475ee311268b28a9fc598a4efd22696d1208.zip cpython-f98d475ee311268b28a9fc598a4efd22696d1208.tar.gz cpython-f98d475ee311268b28a9fc598a4efd22696d1208.tar.bz2 |
[3.11] gh-105375: Improve error handling in the sys extension module (#105611) (#105666)
(cherry picked from commit 41cddc2e93a285b81fa30ac542b088bd9d0112e9)
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
Diffstat (limited to 'Python/sysmodule.c')
-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 8bab703..84f1738 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2360,15 +2360,21 @@ _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_True; Py_INCREF(value); } 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; @@ -3019,15 +3025,21 @@ 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_True; Py_INCREF(value); } 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; |