From 14ed8b8810508d284df21a06b14093537a24e4cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Thu, 16 Sep 2021 23:31:07 +0100 Subject: [PATCH] rmdir: fix uninitialized memory causing incorrect error * 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 149d4659a9..c6e2aba0f2 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))) { /* Ensure the last component was a symlink. */ char* dir_arg = xstrdup (dir); -- 2.47.2