From: Martin v. Löwis Date: Mon, 24 Jul 2006 12:57:47 +0000 (+0000) Subject: Bug #1524310: Properly report errors from FindNextFile in os.listdir. X-Git-Tag: v2.4.4c1~152 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3f1ab7255868ea2a496bb7ea84607b9e033032d;p=thirdparty%2FPython%2Fcpython.git Bug #1524310: Properly report errors from FindNextFile in os.listdir. --- diff --git a/Misc/NEWS b/Misc/NEWS index 715a7a92c12c..e18a3c8a34cc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.4.4c1? Core and builtins ----------------- +- Bug #1524310: Properly report errors from FindNextFile in os.listdir. + - Bug #927248: Recursive method-wrapper objects can now safely be released. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 1e6640e42cd7..8d0363e7ddf2 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1512,6 +1512,13 @@ posix_listdir(PyObject *self, PyObject *args) Py_DECREF(v); } while (FindNextFileW(hFindFile, &wFileData) == TRUE); + if (d && GetLastError() != ERROR_NO_MORE_FILES) { + Py_DECREF(d); + win32_error_unicode("FindNextFileW", wnamebuf); + FindClose(hFindFile); + return NULL; + } + if (FindClose(hFindFile) == FALSE) { Py_DECREF(d); return win32_error_unicode("FindClose", wnamebuf); @@ -1566,6 +1573,13 @@ posix_listdir(PyObject *self, PyObject *args) Py_DECREF(v); } while (FindNextFile(hFindFile, &FileData) == TRUE); + if (d && GetLastError() != ERROR_NO_MORE_FILES) { + Py_DECREF(d); + win32_error("FindNextFileW", namebuf); + FindClose(hFindFile); + return NULL; + } + if (FindClose(hFindFile) == FALSE) { Py_DECREF(d); return win32_error("FindClose", namebuf);