From e3f1ab7255868ea2a496bb7ea84607b9e033032d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 24 Jul 2006 12:57:47 +0000 Subject: [PATCH] Bug #1524310: Properly report errors from FindNextFile in os.listdir. --- Misc/NEWS | 2 ++ Modules/posixmodule.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) 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); -- 2.47.3