Bug 316300 - Deletion of home folder if when having typed "rm -rf <something>" on the terminal I navigate to the home folder
Summary: Deletion of home folder if when having typed "rm -rf <something>" on the term...
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Unclassified
Component: panels: terminal (show other bugs)
Version: 2.2
Platform: Fedora RPMs Linux
: NOR critical (vote)
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords: reproducible
Depends on:
Blocks:
 
Reported: 2013-03-07 11:23 UTC by Jack Gurulian
Modified: 2013-04-04 07:41 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.10.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Gurulian 2013-03-07 11:23:16 UTC
I had a folder that I extracted from a zip file and contained "bad" characters, so I could not delete it via dolpin. I opened the terminal by hitting f4 and typed "rm -rf <first half of folder name and was about to use * because the bad characters could not be autocompleted>". Before hitting enter (or adding the *) I navigated to my home folder. When I did so, my whole home folder was wipped and my data lost! I was lucky I just lost only 5 days of work.

Reproducible: Always

Steps to Reproduce:
1. open a terminalin dolphin by hitting f4
2. type "rm -rf <something>
3. before hitting enter navigate to your home folder
4. DON'T TRY THIS IN YOUR WORKING SYSTEM/USER
Actual Results:  
the home folder was completely gone

Expected Results:  
avoided running a command that I did not type
Comment 1 Jack Gurulian 2013-03-07 11:28:35 UTC
The last logs that were kept in .bash_history:

rm -rf The\ Boy- cd /home/jack
clear
Comment 2 Frank Reininghaus 2013-03-07 22:45:43 UTC
Thanks for the bug report! Actually, we do have some code in place which is supposed to prevent this "accidental home directory deletion".

Nonetheless, I could reproduce this once with a new user, but only the very first time I tried. When I then created new directories and files and tried again, the protection code worked as it should.

I was a bit puzzled first, but looking at the code, it seems that the protection works only if at least once the directory was changed, such that an automatic "cd" was sent to the terminal panel. For every following "cd", the current command is aborted, just not for the first one.

What's strange is that the code looks like this is intentional (the m_clearTerminal member, which determines if the current command should be cleared, has been added in the commit that fixed bug 161637).
Comment 3 Frank Reininghaus 2013-03-08 09:58:35 UTC
Further investigation shows that the "protection code" probably worked fine before KDE 4.9, but was then broken by other changes. I think that patch below might fix it, but I'm not near my development machine now and can't test it.

Thanks again for your help and sorry for the trouble you had!

@@ -143,7 +143,7 @@ void TerminalPanel::changeDir(const KUrl& url)
 
 void TerminalPanel::sendCdToTerminal(const QString& dir)
 {
-    if (dir == m_konsolePartCurrentDirectory) {
+    if (!m_clearTerminal && dir == m_konsolePartCurrentDirectory) {
         return;
     }
Comment 4 Jack Gurulian 2013-03-08 11:25:08 UTC
Thank you Frank for your quick reply! Not much data was lost so no worries :)

What I was wondering is, why not trigger a ctrl-c every time an action in dolphin is performed so that what the user has typed gets wiped?
Comment 5 Frank Reininghaus 2013-03-11 18:13:43 UTC
(In reply to comment #4)
> Thank you Frank for your quick reply! Not much data was lost so no worries :)

Thanks, I'm glad to hear that not much harm was done. I've posted a slightly modified patch at https://git.reviewboard.kde.org/r/109431/ . I'll push that soon if nobody finds a problem with it.

> What I was wondering is, why not trigger a ctrl-c every time an action in
> dolphin is performed so that what the user has typed gets wiped?

We always trigger Ctrl+C when we send a "cd" to the terminal, but not the very first time a "cd" is sent. I've tried to always send Ctrl+C, but then I got a crashing bash when the terminal panel was enabled in a non-home folder. With my patch applied, I think it is guaranteed that every "cd" after the full initalisation of the panel will result in Ctrl+C being sent before, such that the bug cannot happen any mroe.
Comment 6 Frank Reininghaus 2013-03-14 23:18:27 UTC
Git commit 6be6988fb8890d830e08a31a29d73e67c7962128 by Frank Reininghaus.
Committed on 15/03/2013 at 00:12.
Pushed by freininghaus into branch 'KDE/4.10'.

Prevent accidental deletion of home directory in Terminal Panel

The protection against unwanted execution of "rm -rf" when changing the
directory while entering the command did not work if there was never any
automatic "cd" command sent to the terminal before.

This patch ensures that Terminal Panel's member m_clearTerminal is
false after the initialization of the panel, such that the protection is
effective after that.
FIXED-IN: 4.10.2
REVIEW: 109431

M  +1    -0    dolphin/src/panels/terminal/terminalpanel.cpp

http://commits.kde.org/kde-baseapps/6be6988fb8890d830e08a31a29d73e67c7962128
Comment 7 Vadim A. Misbakh-Soloviov (mva) 2013-04-04 05:04:08 UTC
Uhm... Is it okay, that I can't reproduce bug in 4.10.1?
dolphin sends ^C to konsolepart before send cd command there and so then command, that entered there is NOT executed. More of that, I personally like that behaviour, since currently it ALWAYS keep current directories synced between konsole panel and dolphin. But the patch, you're talking about will brake that behaviour and syncing will be broken, if it is something already in command line (if I correctly understand it's behaviour);

So, I ask to revert patch and try to discover, why ^C wasn't sent in reporter's case.
Comment 8 Vadim A. Misbakh-Soloviov (mva) 2013-04-04 05:17:29 UTC
(In reply to comment #2)
> I was a bit puzzled first, but looking at the code, it seems that the
> protection works only if at least once the directory was changed, such that
> an automatic "cd" was sent to the terminal panel. For every following "cd",
> the current command is aborted, just not for the first one.

Uh, okay, I missed that ;)

Anyway, I think it is a bad idea to not sync directories is a bad idea (isn't it a behaviour of m_clearTerminal?)
Comment 9 Frank Reininghaus 2013-04-04 07:41:16 UTC
(In reply to comment #8)
> Anyway, I think it is a bad idea to not sync directories is a bad idea
> (isn't it a behaviour of m_clearTerminal?)

Are you saying that the terminal directory and the view URL are not synced any more for you in KDE 4.10.2? If yes, please open a new bug report for that and provide steps that can be used to reproduce your problem. Thanks.