Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[Patch] No warnings for `rm /*`



Hi all,
I was reading a reddit thread today about shells protecting you from `rm -rf /` but not `rm -rf /*` and remembered how zsh has a feature that warns you before executing `rm *` or `rm /dir/*`. After a short investigation (and the loss of a few files, but that's beside the point), I discovered that zsh warns in every case except `rm /*`.

This seemed like a serious oversight, so I cloned the repository and made a small patch that should fix this. You can find it attached to this message. I hope you accept this patch, as this is a simple fix that can save many people a lot of trouble.

Thanks,
Glenn
diff --git a/Src/exec.c b/Src/exec.c
index 50eff72..3f0a141 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2902,13 +2902,23 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	    if (s[0] == Star && !s[1]) {
 		if (!checkrmall(pwd))
 		    uremnode(args, node);
-	    } else if (l > 2 && s[l - 2] == '/' && s[l - 1] == Star) {
-		char t = s[l - 2];
-
-		s[l - 2] = 0;
+	    } else if (l >= 2 && s[l - 2] == '/' && s[l - 1] == Star) {
+		char t;
+		if (l > 2) {
+		    t = s[l - 2];
+		    s[l - 2] = 0;
+		} else {
+		    t = s[l - 1];
+		    s[l - 1] = 0;
+		}
 		if (!checkrmall(s))
 		    uremnode(args, node);
-		s[l - 2] = t;
+
+		if (l > 2) {
+		    s[l - 2] = t;
+		} else {
+		    s[l - 1] = t;
+		}
 	    }
 	}
 	if (!nextnode(firstnode(args)))


Messages sorted by: Reverse Date, Date, Thread, Author