rm: Fix regression from b278710

The forbidden() function only checks if we are trying to remove one of
the . .. or / directories that are forbidden by POSIX, and it should
not fail when it cannot stat a target, because that check is done later
considering if -r, -f and -i were used or not. If the stat fails we can
be sure that is not / and thus it is not a forbidden target.
This commit is contained in:
Roberto E. Vargas Caballero 2025-05-02 10:41:35 +02:00
parent b27871013b
commit cfe9424ba9

2
rm.c
View File

@ -33,7 +33,7 @@ forbidden(char *path, struct stat *root)
}
if (stat(path, &st) < 0)
eprintf("stat argument '%s':", path);
return 0;
if (st.st_dev == root->st_dev && st.st_ino == root->st_ino) {
if (!w2)
weprintf("\"/\" may not be removed\n");