forwarding to gnulib. Have a nice day, Berny
-------- Forwarded Message -------- Subject: [Bug 984910] rm fails to detect errors in readdir(3) Date: Wed, 15 Jun 2016 19:26:24 +0000 From: bugzilla_nore...@novell.com Andreas Stieger changed bug 984910 <http://bugzilla.opensuse.org/show_bug.cgi?id=984910> -------------------------------------- openSUSE bug report by: Peter Benie <pjb1...@cam.ac.uk> rm, and anything else in coreutils using the fts functions, fails to detect errors in readdir(3). Thankfully such errors are rare, but an example of where they can occur is where a NFS server has a poor readdir cookie implementation. The very latest upsteam coreutils uses the fts functions that are built into libc. In OpenSuSE 13.2 it uses its own copy of fts. The error is in lib/fts.c:fts_read(), which calls readdir() without correctly checking the error return. readdir returns NULL on end-of-directory or on error; fts_read assumes that NULL always means end-of-directory. Patch attached. Peter
--- coreutils-8.23/lib/fts.c~ 2014-06-25 09:43:35.000000000 +0100 +++ coreutils-8.23/lib/fts.c 2016-06-15 19:12:08.517298812 +0100 @@ -1448,9 +1448,16 @@ while (cur->fts_dirp) { bool is_dir; size_t d_namelen; + int errno_before_readdir = errno; + __set_errno (0); struct dirent *dp = readdir(cur->fts_dirp); - if (dp == NULL) + if (dp == NULL) { + cur->fts_info = FTS_DNR; + cur->fts_errno = errno; break; + } else { + __set_errno (errno_before_readdir); + } if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) continue;