[Python-checkins] gh-105375: Improve posix error handling (#105592)
erlend-aasland
webhook-mailer at python.org
Fri Jun 9 16:07:55 EDT 2023
https://github.com/python/cpython/commit/f668f73bc88cce0112b304d87aa998fb28013c71
commit: f668f73bc88cce0112b304d87aa998fb28013c71
branch: main
author: Erlend E. Aasland <erlend.aasland at protonmail.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-06-09T22:07:47+02:00
summary:
gh-105375: Improve posix error handling (#105592)
Fix a bug where an IndexError could end up being overwritten.
files:
A Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst
M Modules/posixmodule.c
diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst
new file mode 100644
index 000000000000..e000f98828a2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-06-09-21-30-59.gh-issue-105375.eewafp.rst
@@ -0,0 +1,2 @@
+Fix a bug in the :mod:`posix` module where an exception could be
+overwritten.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6f01b70d5281..694cff19d228 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6414,7 +6414,7 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
{
Py_ssize_t i, pos, envc;
PyObject *keys=NULL, *vals=NULL;
- PyObject *key, *val, *key2, *val2, *keyval;
+ PyObject *key2, *val2, *keyval;
EXECV_CHAR **envlist;
i = PyMapping_Size(env);
@@ -6439,10 +6439,14 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
}
for (pos = 0; pos < i; pos++) {
- key = PyList_GetItem(keys, pos);
- val = PyList_GetItem(vals, pos);
- if (!key || !val)
+ PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
+ if (key == NULL) {
goto error;
+ }
+ PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
+ if (val == NULL) {
+ goto error;
+ }
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
if (!PyUnicode_FSDecoder(key, &key2))
More information about the Python-checkins
mailing list