[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#22031: Bug in rm command
From: |
Assaf Gordon |
Subject: |
bug#22031: Bug in rm command |
Date: |
Fri, 27 Nov 2015 18:21:29 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
tag 22031 notabug
close 22031
stop
Hello,
On 11/27/2015 09:03 AM, Sneha Mishra wrote:
Steps to get the error:
>cd ~
>mkdir some_directory
>cd some_directory
>vi ~
"enter some text"
then Press <Esc> :wq!
>rm -rf ./*
Your home directory gets deleted.
I am not able to reproduce such scenario on an Ubuntu 15.04/64bit.
Could you provide more details about your operating system and 'rm' version?
First, I will assume these commands were using GNU Coreutils
(and not others, such as BSD or Mac OS X versions), and you were using a modern
shell with common settings (e.g. bash).
If we ignore the 'vi' part, the sequence is:
$ cd ~
$ mkdir some_directory
$ cd some_directory
$ rm -rf ./*
The output should be nothing, and no files should be deleted.
The reason is that "some_directory" is empty,
and so the shell glob "./*" matches no files, and thus is passed
on to 'rm' as if it was a file name.
because of the '-f' parameter, rm silently ignore non-existing files.
If we repeat the same sequence without '-f', the output will be:
$ cd ~
$ mkdir some_directory
$ cd some_directory
$rm -r ./*
rm: cannot remove ‘./*’: No such file or directory
Now, examining the affect of 'vi':
On Ubuntu 15.04 using VIM 7.4, the command:
$ vi ~
results in VI starting with a warning message saying "~ is a directory" -
it does not open a file, and just "typing some text" then pressing <ESC> :wq!
does not result in saving any files (it again displays the error message "~ is a
directory").
Running 'vi' (if it is not an alias or a shell script) should also not modify
your current directory
and so the 'rm' is still executed from inside 'some_directory' .
Somewhat differently, On FreeBSD 10.1, running "vi ~" results in opening the
directory entry as a binary
file (which perhaps could theoretically lead to corrupted filesystem), but
saving the 'file' is not possible.
If you repeat the exact sequence as above, *except* the rm command,
are there any files/links that exist in 'some_directory' ?
regards,
- assaf