zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: "Jonas Bräutigam" <jonas@braeutigamj.de>, zsh-workers@zsh.org
Subject: Re: [Bug] incorrect warning when I type rm /*
Date: Wed, 1 Jul 2020 13:33:22 +0200	[thread overview]
Message-ID: <CAHYJk3SYk1yJyf9eoUwouyfZ924=kC-S2+YpT286_Y=BwU4xEA@mail.gmail.com> (raw)
In-Reply-To: <20200701110025.38f498d5@tarpaulin.shahaf.local2>

On 7/1/20, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Jonas Bräutigam wrote on Wed, 01 Jul 2020 12:02 +0200:
>> Hello,
>>
>> these days I wrote a command wrong. Instead of
>>
>> "$ rm ./*" <- deleting  in the current directory
>>
>> I wrote:
>>
>> "$ rm /*" <- deleting in the root path "/"
>>
>> zsh warn me with:
>>
>> "zsh: sure you want to delete all 4 files in /home/[user]/Downloads
>> [yn]?"
>>
>> After I typed "y", it tried to delete the files in "/".
>>
>> So the correct warning should be:
>>
>> "zsh: sure you want to delete all X files in / [yn]?"
>>
>>
>> I use debian 10.4 with no "rm"-specifiy plugin.
>>
>>
>> Whatch out If you try it! :D
>
> Thanks; it's a path arithmetic edge case:
>
> diff --git a/Src/exec.c b/Src/exec.c
> index 045b5d2b9..7120a2c34 100644
> --- a/Src/exec.c
> +++ b/Src/exec.c
> @@ -3401,7 +3401,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
>  		int rmall;
>
>  		s[l - 2] = 0;
> -		rmall = checkrmall(s);
> +		rmall = checkrmall(l == 2 ? "/" : s);
>  		s[l - 2] = t;
>
>  		if (!rmall) {
>
> The "Is the dir empty?" logic likewise operated on $PWD rather than /,
> so if someone runs «rm /*» as root in an empty directory, the
> RM_STAR_SILENT confirmation prompt would not appear at all.
>
> I haven't figured out how to write a test for this (short of using
> expect(1) or so).

zpty_start and variants as in W02jobs, X02zlevi and others?

-- 
Mikael Magnusson

  reply	other threads:[~2020-07-01 11:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 10:02 Jonas Bräutigam
2020-07-01 11:00 ` Daniel Shahaf
2020-07-01 11:33   ` Mikael Magnusson [this message]
2020-07-01 12:50     ` Daniel Shahaf
2020-07-03 13:41     ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3SYk1yJyf9eoUwouyfZ924=kC-S2+YpT286_Y=BwU4xEA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=jonas@braeutigamj.de \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).