Date: Sat, 2 Oct 2004 11:33:41 +0300 From: Giorgos Keramidas <keramida@freebsd.org> To: freebsd-hackers@freebsd.org Subject: Re: Protection from the dreaded "rm -fr /" Message-ID: <20041002083341.GB21439@gothmog.gr> In-Reply-To: <20041002081928.GA21439@gothmog.gr> References: <20041002081928.GA21439@gothmog.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-10-02 11:19, Giorgos Keramidas <keramida@FreeBSD.org> 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. */ %%%
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041002083341.GB21439>