From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 4 23:30:02 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2F8845DF for ; Tue, 4 Mar 2014 23:30:02 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1B69CBBC for ; Tue, 4 Mar 2014 23:30:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s24NU1TE020291 for ; Tue, 4 Mar 2014 23:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s24NU1m2020290; Tue, 4 Mar 2014 23:30:01 GMT (envelope-from gnats) Date: Tue, 4 Mar 2014 23:30:01 GMT Message-Id: <201403042330.s24NU1m2020290@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: bin/187264: rm command: rm -r file1 file2 "" does not remove existing files or directories X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Mar 2014 23:30:02 -0000 The following reply was made to PR bin/187264; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, jlw@xinuos.com Cc: Subject: Re: bin/187264: rm command: rm -r file1 file2 "" does not remove existing files or directories Date: Wed, 5 Mar 2014 00:23:15 +0100 In PR bin/187264, you wrote: > When the gmake/make clean target contains a command of the form > rm -rf "a.out" "$(DSYM)" main.o main.d > the command fails to remove any of the existing files if DSYM is null. > The '-f' option hides the error associated with the zero length file > name, but gives no indication that, in fact, NO files/directories have > been removed. I can reproduce this, not only with rm, but also with ls, cp and find. The underlying fts_open(3) fails if any pathname is empty and causes the entire command to fail. If a pathname otherwise does not refer to an existing file, this correctly does not prevent processing of other pathnames. The below patch makes fts_open(3) treat an empty pathname like any other pathname that cannot be lstatted because of [ENOENT]. It is lightly tested. Index: lib/libc/gen/fts.c =================================================================== --- lib/libc/gen/fts.c (revision 262358) +++ lib/libc/gen/fts.c (working copy) @@ -161,11 +161,7 @@ fts_open(argv, options, compar) /* Allocate/initialize root(s). */ for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; - goto mem3; - } + len = strlen(*argv); p = fts_alloc(sp, *argv, len); p->fts_level = FTS_ROOTLEVEL; -- Jilles Tjoelker