From owner-freebsd-stable@FreeBSD.ORG Mon Oct 1 04:38:01 2007 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ACF6B16A41A for ; Mon, 1 Oct 2007 04:38:01 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from gaia.nimnet.asn.au (nimbin.lnk.telstra.net [139.130.45.143]) by mx1.freebsd.org (Postfix) with ESMTP id 16E3713C48A for ; Mon, 1 Oct 2007 04:37:59 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (smithi@localhost) by gaia.nimnet.asn.au (8.8.8/8.8.8R1.5) with SMTP id OAA06102; Mon, 1 Oct 2007 14:37:40 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Mon, 1 Oct 2007 14:37:39 +1000 (EST) From: Ian Smith To: Mark Andrews In-Reply-To: <200709262333.l8QNXAI4058907@drugs.dv.isc.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: freebsd-stable@freebsd.org, LI Xin Subject: Re: rm(1) bug, possibly serious X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Oct 2007 04:38:01 -0000 On Thu, 27 Sep 2007, Mark Andrews wrote: (I wrote:) > > On Tue, 25 Sep 2007, LI Xin wrote: > > > Oliver Fromme wrote: > > > > Nicolas Rachinsky wrote: > > > > > Oliver Fromme wrote: > > > > > > By the way, an additional confusion is that ".." and "../" > > > > > > are handled differently. Specifying ".." always leads to > > > > > > this message: > > > > > > > > > > > > rm: "." and ".." may not be removed > > > > > > > > > > > > and nothing is actually removed. It is confusing that > > > > > > adding a slash leads to a different error message _and_ > > > > > > removal of the contents of the parent directory. Clearly > > > > > > a POLA violation. > > > > Clearly a bug, and well spotted, especially if as old as reported. > > > > > > > > > > > > Adding a slash often leads to different behaviour. > > > > > > > > Yes, I'm aware of that. I often make use of the feature > > > > that "find /sys/" expands the symlink, while "find /sys" > > > > does not. The same holds true for ls(1). > > > > But fortunately not for rm(1): > > > > The rm utility removes symbolic links, not the files referenced by the > > links. > > > > It is an error to attempt to remove the files /, . or .. > > > > > > However, I would still argue that there is no sane reason > > > > for "rm -rf ../" behaving differently from "rm -rf ..", > > > > especially because it behaves differently in a destructive > > > > way. That's why I call it a POLA violation. > > > > > > Also a POSIX violation IMHO :-) > > > > Indeed; I can't imagine a situation where removing "." (let alone "..") > > and so orphaning the pwd might be considered sane, never mind legal .. > > but maybe I lack imagination :) > > You lack imagination. No doubt :) > When you found the directory you want to remove and you are > in it it is much less error prone to remove "." recursively > that to go up one directory and try to find the directory > you were just in. Sorry, I can't agree. I take comfort in knowing that 'rm .' will fail, that 'rm *' will not remove '.' (let alone '..'!), and that rm will not orphan the pwd. Neither will umount, for that matter .. > The the prohibitions comes from when you literally removed > directories by unlinking the directory and "." and ".." > within the directory in user space. It was easy to stuff > up a directory structure. Regardless of how implemented in the filesystem, having the pwd become invalid isn't something I ever expect to happen, and I'll continue to rely on: 'It is an error to attempt to remove the files /, . or ..' Cheers, Ian