On 2004-10-02 11:19, Giorgos Keramidas <[EMAIL PROTECTED]> wrote:
> John Beck, who works for Sun, has posted an entry in his blog yesterday
> about "rm -fr /" protection, which I liked a lot:
> http://blogs.sun.com/roller/page/jbeck/20041001#rm_rf_protection

Here's a simpler diff, which I wrote after I looked a bit in the
while-loop I had and realized it was really an obfuscated for-loop:

%%%
Index: rm.c
===================================================================
RCS file: /home/ncvs/src/bin/rm/rm.c,v
retrieving revision 1.47
diff -u -r1.47 rm.c
--- rm.c        6 Apr 2004 20:06:50 -0000       1.47
+++ rm.c        2 Oct 2004 08:28:36 -0000
@@ -157,6 +157,7 @@
 void
 rm_tree(char **argv)
 {
+       char **argv_tmp;
        FTS *fts;
        FTSENT *p;
        int needstat;
@@ -164,6 +165,14 @@
        int rval;
 
        /*
+        * If one of the members of argv[] is the root directory abort the
+        * entire operation.
+        */
+       for (argv_tmp = argv; *argv_tmp != NULL; argv_tmp++)
+               if (strcmp(*argv_tmp, "/") == 0)
+                       errx(1, "recursive rm of / is not allowed");
+
+       /*
         * Remove a file hierarchy.  If forcing removal (-f), or interactive
         * (-i) or can't ask anyway (stdin_ok), don't stat the file.
         */
%%%
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to