]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
rmdir: fix uninitialized memory causing incorrect error
authorPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 22:31:07 +0000 (23:31 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 22:45:16 +0000 (23:45 +0100)
* src/rmdir.c (main): Only inspect the returned stat structure,
when stat(2) returns success.

src/rmdir.c

index 149d4659a9065cc1998d1c9b6b1fd22acd707cd0..c6e2aba0f2f00bc1662890830878d810a708dc58 100644 (file)
@@ -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)))
                     {
                       /* Ensure the last component was a symlink.  */
                       char* dir_arg = xstrdup (dir);