[dev] [PATCH 2/2] rm: Don't attempt to remove . or ..

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
Date: Thu, 24 Apr 2025 09:50:06 +0200

From: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>

POSIX explicitely mandates to ignore . or .. to avoid
pitfals like rm -r .* and no having files that begin
with a dot.
---
 rm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/rm.c b/rm.c
index 2391d68..1f23c09 100644
--- a/rm.c
+++ b/rm.c
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <fcntl.h>
+#include  <string.h>
 
 #include "fs.h"
 #include "util.h"
_AT_@ -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;
 }
-- 
2.46.1
Received on Thu Apr 24 2025 - 09:50:06 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 24 2025 - 10:00:11 CEST