Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1089631

Browse filesBrowse files
erlend-aaslandpull[bot]
authored andcommitted
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.
1 parent a89dbf8 commit 1089631
Copy full SHA for 1089631

File tree

Expand file treeCollapse file tree

2 files changed

+20
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-6
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix bugs in :mod:`sys` where exceptions could end up being overwritten
2+
because of deferred error handling.

‎Python/sysmodule.c

Copy file name to clipboardExpand all lines: Python/sysmodule.c
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,14 +2721,20 @@ _PySys_AddXOptionWithError(const wchar_t *s)
27212721
const wchar_t *name_end = wcschr(s, L'=');
27222722
if (!name_end) {
27232723
name = PyUnicode_FromWideChar(s, -1);
2724+
if (name == NULL) {
2725+
goto error;
2726+
}
27242727
value = Py_NewRef(Py_True);
27252728
}
27262729
else {
27272730
name = PyUnicode_FromWideChar(s, name_end - s);
2731+
if (name == NULL) {
2732+
goto error;
2733+
}
27282734
value = PyUnicode_FromWideChar(name_end + 1, -1);
2729-
}
2730-
if (name == NULL || value == NULL) {
2731-
goto error;
2735+
if (value == NULL) {
2736+
goto error;
2737+
}
27322738
}
27332739
if (PyDict_SetItem(opts, name, value) < 0) {
27342740
goto error;
@@ -3374,14 +3380,20 @@ sys_add_xoption(PyObject *opts, const wchar_t *s)
33743380
const wchar_t *name_end = wcschr(s, L'=');
33753381
if (!name_end) {
33763382
name = PyUnicode_FromWideChar(s, -1);
3383+
if (name == NULL) {
3384+
goto error;
3385+
}
33773386
value = Py_NewRef(Py_True);
33783387
}
33793388
else {
33803389
name = PyUnicode_FromWideChar(s, name_end - s);
3390+
if (name == NULL) {
3391+
goto error;
3392+
}
33813393
value = PyUnicode_FromWideChar(name_end + 1, -1);
3382-
}
3383-
if (name == NULL || value == NULL) {
3384-
goto error;
3394+
if (value == NULL) {
3395+
goto error;
3396+
}
33853397
}
33863398
if (PyDict_SetItem(opts, name, value) < 0) {
33873399
goto error;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.