Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :cc;
        bh=PTk3I1cKtRdPHQyEj26AC+CbGOow0nGhn7npJT8unQs=;
        b=R4JnNByRoKawo2PE/j+aYPG0GDgQ+P+e0uVVfPdL1RAZNYLcvXctqv/3nLu2yyDxaR
         U+IoirX9MqAxaWv+yi49T2FStKNFa/WKXoN0mDjofWNuKZER9L/gpjIem923qowanavN
         x0Qh8shlOpeTRST9L6gP49FZcwXiKlNuuT5IqCT5zdbOApRXKCa75zYWyq811PqYatNb
         gHqdhPhzCbmMsfygBVuFjxyQoOrB28VxHGXw0hX298ZzjVnKXIGqFOHwAzAtzC6pPdDJ
         vtkc9kxfk4SHr0Xux796CdLtEBtKcM+qBhHHcyUUeyv3CyibM1y+lh6dXr0whSJTMeDm
         Bxgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:cc;
        bh=PTk3I1cKtRdPHQyEj26AC+CbGOow0nGhn7npJT8unQs=;
        b=GYuSNceMy8jy6/ppR1Ax1dqIhGXVRpLxq6ady0TZVWW+giLczPPtl5Ms3xA6fM/7vB
         lRp4NvXyVSVQeL3YLzjOrzBHPK9wHAJ+kv8wlylvfnOx65psgDqrz4cTAKmYz/mmoJ4X
         iu/7TEeWBjclCMcPJoKctav6WETCJ7IXobdAuVkwB7EE1G5b0NoHjfygB7AOygK4kqzl
         tMg9HTdOuDli/LuS7x162xs2PW1U/dHL7A4Z5H0gPsDk/wXG5leyDB+mAoXloCxdaQR6
         8qNFjcPbHu9SnkCJYlMAbhmfx29hIjMbUctsaCoRzzPvDjyrncxfCo0WY5pXKdNzhTBa
         BYsQ==
X-Gm-Message-State: AOPr4FUHtskVN+Joi3S5YaA449aL+qM9RigUc7J11t3uWRxkTSOvF9/0TtyEqCJc/OhsMf6kd84guzcJBswyYQ==
MIME-Version: 1.0
X-Received: by 10.55.47.70 with SMTP id v67mr3699431qkh.135.1461694128179;
 Tue, 26 Apr 2016 11:08:48 -0700 (PDT)
In-Reply-To: <160426103624.ZM11049@torch.brasslantern.com>
References: <CAN3Cs_H0Uz8c7Du53UfvoRcob5zcU8KkNeqHn6vVGaguxNHK9A@mail.gmail.com>
	<160426103624.ZM11049@torch.brasslantern.com>
Date: Tue, 26 Apr 2016 20:08:48 +0200
Message-ID: <CAHYJk3QXkpsE=ACQy=brwbKKL5S-cdaWDQ6CUccSs+RzJ-ybXA@mail.gmail.com>
Subject: Re: [Patch] No warnings for `rm /*`
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh workers <zsh-workers@zsh.org>
Content-Type: text/plain; charset=UTF-8
X-Seq: zsh-workers 38351

On Tue, Apr 26, 2016 at 7:36 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Apr 26, 10:31am, Glenn Smith wrote:
> } Subject: [Patch] No warnings for `rm /*`
> }
> } I discovered that zsh warns in every case except `rm /*`.
>
> Thanks.  I think the following simpler patch does the same.
>
> diff --git a/Src/exec.c b/Src/exec.c
> index 50eff72..2dcd5bc 100644
> --- a/Src/exec.c
> +++ b/Src/exec.c
> @@ -2902,11 +2902,11 @@ 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) {
> +           } else if (l >= 2 && s[l - 2] == '/' && s[l - 1] == Star) {
>                 char t = s[l - 2];
>
>                 s[l - 2] = 0;
> -               if (!checkrmall(s))
> +               if (!checkrmall(*s ? s : "/"))
>                     uremnode(args, node);
>                 s[l - 2] = t;
>             }
>
>
> As an aside:
>
> % rm /nonexistentdir/*
> zsh: sure you want to delete all the files in /nonexistentdir [yn]?
>
> Seems like we could detect when opendir() fails with ENOENT and skip
> the prompt, but maybe there are cases of race condition (directory is
> created after I type "rm ..." but before /bin/rm is executed?) where
> the default answer of "y" would be incorrect.

This is pretty contrived, but it's not even a race condition.

% mkdir /tmp/r; rm /tmp/r/.(e:'echo hello; touch $REPLY/foo:') /tmp/r/*
zsh: sure you want to delete all the files in /tmp/r [yn]? y
hello
rm: cannot remove '/tmp/r/.': Is a directory
removed '/tmp/r/foo'

-- 
Mikael Magnusson

