From: Georg Brandl Date: Tue, 11 Apr 2006 06:51:25 +0000 (+0000) Subject: Bug #1467952: backport: make os.listdir() raise if readdir() fails X-Git-Tag: v2.4.4c1~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=653d87d1d7fb0fec5655b3745293c1a2b5d431ff;p=thirdparty%2FPython%2Fcpython.git Bug #1467952: backport: make os.listdir() raise if readdir() fails --- diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index f4ec089eebc8..89288536b89a 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -540,7 +540,8 @@ documentation; flag constants (like \constant{O_RDONLY} and This function is intended for low-level I/O. For normal usage, use the built-in function \function{open()}, which returns a ``file object'' with \method{read()} and \method{write()} methods (and many -more). +more). To wrap a file descriptor in a ``file object'', use +\function{fdopen()}. \end{notice} \end{funcdesc} diff --git a/Misc/NEWS b/Misc/NEWS index cf63a7dd78e0..e1cf2ef52cea 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,6 +15,9 @@ Core and builtins Extension Modules ----------------- +- Bug #1467952: os.listdir() now correctly raises an error if readdir() + fails with an error condition. + - Fix bsddb.db.DBError derived exceptions so they can be unpickled. Library diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e92f69e79fe3..1a514692a0d7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1699,6 +1699,12 @@ 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);