Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Sep 2007 21:53:37 GMT
From:      Justin Mitchell <freebsd.20.skel@spamgourmet.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/116477: rm behaves unexpectedly when using -r and relative paths
Message-ID:  <200709192153.l8JLrbXo040792@www.freebsd.org>
Resent-Message-ID: <200709192200.l8JM06Bt064472@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         116477
>Category:       bin
>Synopsis:       rm behaves unexpectedly when using -r and relative paths
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 19 22:00:05 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Justin Mitchell
>Release:        Mac OS X 10.4
>Organization:
>Environment:
Darwin justin-mitchells-mac-mini.local 8.10.0 Darwin Kernel Version 8.10.0: Wed May 23 16:50:59 PDT 2007; root:xnu-792.21.3~1/RELEASE_PPC Power Macintosh powerpc
>Description:
This is a bug with the 'rm' commandline utility that can cause data
loss.

When using 'rm -r' with relative paths and a trailing slash rm can
delete the wrong item, or no item at all. Here is an example of rm
deleting the wrong file.

mac:~ $ mkdir tmp
mac:~ $ cd tmp
mac:~/tmp $ mkdir test
mac:~/tmp $ ln -s test test2
mac:~/tmp $ ls -l
total 8
drwxr-xr-x   2 justin  justin  68 Aug 10 01:41 test
lrwxr-xr-x   1 justin  justin   4 Aug 10 01:42 test2 -> test
mac:~/tmp $ cd ..
mac:~ $ rm -r tmp/test2/
mac:~ $ ls -l tmp
total 8
lrwxr-xr-x   1 justin  justin  4 Aug 10 01:42 test2 -> test

Note that if you do you not use the trailing slash in 'rm -f tmp/
test2/' that it will behave normally. It will also behave normally if
you do not 'cd' to another directory.

I confirmed this with another individual running OS X, but I do
not know the version. For comparison, I tested this with an older
version of Redhat, and it worked fine.

I submitted this bug report to Apple, but they said "This is how FreeBSD operates and rm is based on their sources." 

>How-To-Repeat:
mac:~ $ mkdir tmp
mac:~ $ cd tmp
mac:~/tmp $ mkdir test
mac:~/tmp $ ln -s test test2
mac:~/tmp $ ls -l
total 8
drwxr-xr-x   2 justin  justin  68 Aug 10 01:41 test
lrwxr-xr-x   1 justin  justin   4 Aug 10 01:42 test2 -> test
mac:~/tmp $ cd ..
mac:~ $ rm -r tmp/test2/
mac:~ $ ls -l tmp
total 8
lrwxr-xr-x   1 justin  justin  4 Aug 10 01:42 test2 -> test
>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709192153.l8JLrbXo040792>