Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[Patch] No warnings for `rm /*`
- X-seq: zsh-workers 38348
- From: Glenn Smith <glennsmith2209@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [Patch] No warnings for `rm /*`
- Date: Tue, 26 Apr 2016 10:31:41 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to; bh=hfV+8/9stM61Dlm5e+2JKvAhlHMmiLuheCKBSF+rUvY=; b=aOdeVaxVYqkHTJgOwosJUAKXjHXw3T4+zt1MFODGn6Wd8Cq78z3iy3tj5LFxmw7bOJ NpoCS2Cqh0DRQStzPJO7tELbZ7v4rsv25fr0Td2xpq3LzAP9CUzW48kHq30ykXs+ev60 2IWlEcmcIsQuwyCiu2shGhjz3eKdB7AWHFx+dkUYexINhpdUA4hE7ABfkfBQZjC8uBHP HvXKXwCnN1GliukTA3/BX8QseSGsrIUxKaIihrSI33vIBm+CjrXtCxUb1lvfKkTuSBkx UmW51h8mLv2tDcLXiGmsqlQb3qboyfLwk4EaOhAPfE2dI5Rz1APMg4y8QeEAH9xCjtM2 N1YA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Sender: gssrox001@xxxxxxxxx
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