From: Georg Brandl Date: Tue, 11 Apr 2006 06:47:43 +0000 (+0000) Subject: Bug #1467952: os.listdir() now correctly raises an error if readdir() X-Git-Tag: v2.5a2~347 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbfe4fad361e7190675f28702332ddc377bd8cfd;p=python Bug #1467952: os.listdir() now correctly raises an error if readdir() fails with an error condition. --- diff --git a/Misc/NEWS b/Misc/NEWS index 7418daa173..4dacebd081 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -41,6 +41,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 bc966817a7..39765b2b91 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1901,6 +1901,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);