Similar to the FTS readdir fix in v4.6.0-72-g155c9d1, handle the last two unhandled readdir(3) errors.
* find/pred.c (pred_empty): Do the above. * lib/fdleak.c (get_proc_max_fd): Likewise. While at it, fix the condition to only skip "." and ".."; previously, also other files beginning with ".." would have been skipped - that was theoretically, as we only expect the FD files in "/proc/self/fd". --- find/pred.c | 8 ++++++++ lib/fdleak.c | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/find/pred.c b/find/pred.c index f7e9b59..93f82b6 100644 --- a/find/pred.c +++ b/find/pred.c @@ -380,6 +380,7 @@ pred_empty (const char *pathname, struct stat *stat_buf, struct predicate *pred_ state.exit_status = 1; return false; } + errno = 0; for (dp = readdir (d); dp; dp = readdir (d)) { if (dp->d_name[0] != '.' @@ -390,6 +391,13 @@ pred_empty (const char *pathname, struct stat *stat_buf, struct predicate *pred_ break; } } + if (errno) + { + /* Handle errors from readdir(3). */ + error (0, errno, "%s", safely_quote_err_filename (0, pathname)); + state.exit_status = 1; + return false; + } if (CLOSEDIR (d)) { error (0, errno, "%s", safely_quote_err_filename (0, pathname)); diff --git a/lib/fdleak.c b/lib/fdleak.c index 5dc4cb1..cf19fa2 100644 --- a/lib/fdleak.c +++ b/lib/fdleak.c @@ -19,6 +19,7 @@ /* system headers. */ #include <assert.h> +#include <errno.h> #include <fcntl.h> #include <limits.h> #include <poll.h> @@ -77,11 +78,23 @@ get_proc_max_fd (void) int good = 0; struct dirent *dent; - while ((dent=readdir (dir)) != NULL) - { + while (1) + { + errno = 0; + dent = readdir (dir); + if (NULL == dent) + { + if (errno) + { + error (0, errno, "%s", quotearg_n_style (0, locale_quoting_style, path)); + good = 0; + } + break; + } + if (dent->d_name[0] != '.' - || (dent->d_name[0] != 0 - && dent->d_name[1] != 0 && dent->d_name[1] != '.')) + || (dent->d_name[1] != 0 + && (dent->d_name[1] != '.' || dent->d_name[2] != 0))) { const int fd = safe_atoi (dent->d_name, literal_quoting_style); if (fd > maxfd) -- 2.1.4