On 17/09/2021 00:05, Jim Meyering wrote:
On Thu, Sep 16, 2021 at 3:35 PM Pádraig Brady <p...@draigbrady.com> wrote:
* src/rmdir.c (main): Only inspect the returned stat structure,
when stat(2) returns success.
---
  src/rmdir.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/rmdir.c b/src/rmdir.c
index 149d4659a..c6e2aba0f 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -262,7 +262,8 @@ main (int argc, char **argv)
                    struct stat st;
                    int ret = stat (dir, &st);
                    /* Some other issue following, or is actually a directory. 
*/
-                  if ((ret != 0 && errno != ENOTDIR) || S_ISDIR (st.st_mode))
+                  if ((ret != 0 && errno != ENOTDIR)
+                      || (ret == 0 && S_ISDIR (st.st_mode)))

Good one!
Found via valgrind?

Noticed initially with intermittent failures
when repeatedly testing on centos8.

Valgrind confirmed the issue.

cheers,
Pádraig

Reply via email to