mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.12] gh-105375: Improve error handling in the sys extension module (GH-105611) (#105665)
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
(cherry picked from commit 41cddc2e93
)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
82ac2be6b3
commit
a1034b5fd3
2 changed files with 20 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
|||
Fix bugs in :mod:`sys` where exceptions could end up being overwritten
|
||||
because of deferred error handling.
|
|
@ -2718,15 +2718,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_NewRef(Py_True);
|
||||
}
|
||||
else {
|
||||
name = PyUnicode_FromWideChar(s, name_end - s);
|
||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||
}
|
||||
if (name == NULL || value == NULL) {
|
||||
if (name == NULL) {
|
||||
goto error;
|
||||
}
|
||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||
if (value == NULL) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (PyDict_SetItem(opts, name, value) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -3370,15 +3376,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_NewRef(Py_True);
|
||||
}
|
||||
else {
|
||||
name = PyUnicode_FromWideChar(s, name_end - s);
|
||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||
}
|
||||
if (name == NULL || value == NULL) {
|
||||
if (name == NULL) {
|
||||
goto error;
|
||||
}
|
||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||
if (value == NULL) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (PyDict_SetItem(opts, name, value) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue