summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-07-16 21:31:41 (GMT)
committerGeorg Brandl <georg@python.org>2008-07-16 21:31:41 (GMT)
commit86cbf81b47d8eca31ade71f8d6b0653167ffd922 (patch)
treea10a63d89302963687399681c2c94e3a4ed9f0d8 /Modules/posixmodule.c
parentb32dea5a3eb0c008d00de3a42b1aa0c05bad2d13 (diff)
downloadcpython-86cbf81b47d8eca31ade71f8d6b0653167ffd922.zip
cpython-86cbf81b47d8eca31ade71f8d6b0653167ffd922.tar.gz
cpython-86cbf81b47d8eca31ade71f8d6b0653167ffd922.tar.bz2
#1608818: errno can get set by every call to readdir().
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index d8c81b6..6af6e51 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2322,11 +2322,19 @@ posix_listdir(PyObject *self, PyObject *args)
return NULL;
}
for (;;) {
+ errno = 0;
Py_BEGIN_ALLOW_THREADS
ep = readdir(dirp);
Py_END_ALLOW_THREADS
- if (ep == NULL)
- break;
+ if (ep == NULL) {
+ if (errno == 0) {
+ break;
+ } else {
+ closedir(dirp);
+ Py_DECREF(d);
+ return posix_error_with_allocated_filename(name);
+ }
+ }
if (ep->d_name[0] == '.' &&
(NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
@@ -2363,12 +2371,6 @@ posix_listdir(PyObject *self, PyObject *args)
}
Py_DECREF(v);
}
- if (errno != 0 && d != NULL) {
- /* readdir() returned NULL and set errno */
- closedir(dirp);
- Py_DECREF(d);
- return posix_error_with_allocated_filename(name);
- }
closedir(dirp);
PyMem_Free(name);