summaryrefslogtreecommitdiffstats
path: root/Modules/_winapi.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-19 19:09:56 (GMT)
committerGitHub <noreply@github.com>2017-04-19 19:09:56 (GMT)
commite63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c (patch)
tree4397f11f7bce21bf7e5be3dd8185eb5bf2d78c87 /Modules/_winapi.c
parent49a905958ffc2fcd5d1d1a293ae453d45deeb884 (diff)
downloadcpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.zip
cpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.tar.gz
cpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.tar.bz2
[3.5] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (#1182)
raised an error. (cherry picked from commit bf623ae8843dc30b28c574bec8d29fc14be59d86) (cherry picked from commit 680fea4067537a9b9c79aadd44a3a19e83cd2dbf)
Diffstat (limited to 'Modules/_winapi.c')
-rw-r--r--Modules/_winapi.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index edc6cf4..cc7b663 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -722,17 +722,22 @@ getenvironment(PyObject* environment)
return NULL;
}
- envsize = PyMapping_Length(environment);
-
keys = PyMapping_Keys(environment);
values = PyMapping_Values(environment);
if (!keys || !values)
goto error;
+ envsize = PySequence_Fast_GET_SIZE(keys);
+ if (PySequence_Fast_GET_SIZE(values) != envsize) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "environment changed size during iteration");
+ goto error;
+ }
+
totalsize = 1; /* trailing null character */
for (i = 0; i < envsize; i++) {
- PyObject* key = PyList_GET_ITEM(keys, i);
- PyObject* value = PyList_GET_ITEM(values, i);
+ PyObject* key = PySequence_Fast_GET_ITEM(keys, i);
+ PyObject* value = PySequence_Fast_GET_ITEM(values, i);
if (! PyUnicode_Check(key) || ! PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError,
@@ -760,8 +765,8 @@ getenvironment(PyObject* environment)
end = buffer + totalsize;
for (i = 0; i < envsize; i++) {
- PyObject* key = PyList_GET_ITEM(keys, i);
- PyObject* value = PyList_GET_ITEM(values, i);
+ PyObject* key = PySequence_Fast_GET_ITEM(keys, i);
+ PyObject* value = PySequence_Fast_GET_ITEM(values, i);
if (!PyUnicode_AsUCS4(key, p, end - p, 0))
goto error;
p += PyUnicode_GET_LENGTH(key);