#1608818: errno can get set by every call to readdir().

This commit is contained in:
Georg Brandl 2008-07-16 21:31:41 +00:00
parent b32dea5a3e
commit 86cbf81b47
2 changed files with 12 additions and 8 deletions

View file

@ -63,6 +63,8 @@ Core and Builtins
Library Library
------- -------
- Issue #1608818: Fix misbehavior in os.listdir() if readdir() fails.
- Issue #3125: Remove copy_reg in multiprocessing and replace it with - Issue #3125: Remove copy_reg in multiprocessing and replace it with
ForkingPickler.register() to resolve conflict with ctypes. ForkingPickler.register() to resolve conflict with ctypes.

View file

@ -2322,11 +2322,19 @@ posix_listdir(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
for (;;) { for (;;) {
errno = 0;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
ep = readdir(dirp); ep = readdir(dirp);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (ep == NULL) if (ep == NULL) {
if (errno == 0) {
break; break;
} else {
closedir(dirp);
Py_DECREF(d);
return posix_error_with_allocated_filename(name);
}
}
if (ep->d_name[0] == '.' && if (ep->d_name[0] == '.' &&
(NAMLEN(ep) == 1 || (NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2))) (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
@ -2363,12 +2371,6 @@ posix_listdir(PyObject *self, PyObject *args)
} }
Py_DECREF(v); 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); closedir(dirp);
PyMem_Free(name); PyMem_Free(name);