sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 3f7c7c2497037ff29c84464059ea9a6442596354
parent 0df8cdc12d7a5600ad0c2b9420a14be4e2af340b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 24 Apr 2025 08:51:22 +0200

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.

Diffstat:
Mrm.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/rm.c b/rm.c @@ -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; }