From 653d87d1d7fb0fec5655b3745293c1a2b5d431ff Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 11 Apr 2006 06:51:25 +0000 Subject: Bug #1467952: backport: make os.listdir() raise if readdir() fails --- Doc/lib/libos.tex | 3 ++- Misc/NEWS | 3 +++ Modules/posixmodule.c | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index f4ec089..8928853 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 cf63a7d..e1cf2ef 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 e92f69e..1a51469 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); -- cgit v0.12