summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-11 21:12:17 (GMT)
committerGitHub <noreply@github.com>2023-06-11 21:12:17 (GMT)
commita1034b5fd3af59d813452742153e60b40b39ff4a (patch)
treec83daf641f94dd60c137baa0280c390cf695bcc1 /Python
parent82ac2be6b386b7d106a36262f1aa960f638bde8d (diff)
downloadcpython-a1034b5fd3af59d813452742153e60b40b39ff4a.zip
cpython-a1034b5fd3af59d813452742153e60b40b39ff4a.tar.gz
cpython-a1034b5fd3af59d813452742153e60b40b39ff4a.tar.bz2
[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 41cddc2e93a285b81fa30ac542b088bd9d0112e9) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index e6731e7..a05bdf0 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2718,14 +2718,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;
@@ -3370,14 +3376,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;