rm: Don't attempt to remove . or ..

POSIX explicitely mandates to ignore . or .. to avoid
pitfals like rm -r .* and no having files that begin
with a dot.
This commit is contained in:
Roberto E. Vargas Caballero 2025-04-24 08:51:22 +02:00
parent 0df8cdc12d
commit 3f7c7c2497

7
rm.c
View File

@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <fcntl.h>
#include <string.h>
#include "fs.h"
#include "util.h"
@ -37,8 +38,10 @@ main(int argc, char *argv[])
return 0;
}
for (; *argv; argc--, argv++)
recurse(AT_FDCWD, *argv, NULL, &r);
for (; *argv; argc--, argv++) {
if (strcmp(*argv, ".") && strcmp(*argv, ".."))
recurse(AT_FDCWD, *argv, NULL, &r);
}
return rm_status || recurse_status;
}