From nobody@FreeBSD.org  Tue Mar  4 21:43:35 2014
Return-Path: <nobody@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 7C9855B0
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  4 Mar 2014 21:43:35 +0000 (UTC)
Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 678AAED4
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  4 Mar 2014 21:43:35 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s24LhYlE078219
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 4 Mar 2014 21:43:35 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s24LhYDs078216;
	Tue, 4 Mar 2014 21:43:34 GMT
	(envelope-from nobody)
Message-Id: <201403042143.s24LhYDs078216@cgiserv.freebsd.org>
Date: Tue, 4 Mar 2014 21:43:34 GMT
From: John Wolfe <jlw@xinuos.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: rm command: rm -r file1 file2 "" does not remove existing files or directories
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         187264
>Category:       bin
>Synopsis:       rm command: rm -r file1 file2 "" does not remove existing files or directories
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 04 21:50:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sat Apr  5 20:30:00 UTC 2014
>Originator:     John Wolfe
>Release:        FreeBSD 9.2   (PC-BSD 9.2)
>Organization:
Xinuos, Inc.
>Environment:
FreeBSD sapphire.nj.sco.com 9.2-RELEASE-p12 FreeBSD 9.2-RELEASE-p12 #0: Thu Jan 16 21:12:30 UTC 2014     root@amd64-builder.pcbsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
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.


>How-To-Repeat:
Use the following script to see the problem

rm.bug.sh:
======================
#! /bin/sh
set -x

cat  > file_1 << !EOF
12345
How no brown cow
!EOF
cp file_1 file_2
cp file_1 file_3

# The following command should remove file_[123], but does not.
# The '-r' implies the '-d' option - attempt to remove directories 
# as well as other types of files.    The "" results in an error 
# when treated as a possible directory.
#
#  $ rm -r ""
#  rm: fts_open: No such file or directory
#
# which is a valid error, but none of the arguments are removed.
# 
# When the following command is run without the '-r', all three 
# files are removed.


rm -r "file_1" "" file_[23]

ls -l

# Yet a "rm -r " with a non-existant file in the list, will remove 
# all existing files.

rm -r "file_1" "xxx" file_2

ls -l

>Fix:


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, jlw@xinuos.com
Cc:  
Subject: Re: bin/187264: rm command: rm -r file1 file2 &quot;&quot; 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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/187264: commit references a PR
Date: Thu,  6 Mar 2014 22:47:18 +0000 (UTC)

 Author: jilles
 Date: Thu Mar  6 22:47:11 2014
 New Revision: 262872
 URL: http://svnweb.freebsd.org/changeset/base/262872
 
 Log:
   fts: Don't abort if an empty pathname is given.
   
   Make fts_open(3) treat an empty pathname like any other pathname that cannot
   be lstatted because of [ENOENT].
   
   It is rather confusing if  rm -rf file1 "" file2  does not remove file1 and
   file2.
   
   PR:		bin/187264
   MFC after:	2 weeks
 
 Modified:
   head/lib/libc/gen/fts.c
 
 Modified: head/lib/libc/gen/fts.c
 ==============================================================================
 --- head/lib/libc/gen/fts.c	Thu Mar  6 21:47:22 2014	(r262871)
 +++ head/lib/libc/gen/fts.c	Thu Mar  6 22:47:11 2014	(r262872)
 @@ -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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Fri Mar 7 17:11:02 UTC 2014 
State-Changed-Why:  
Fixed in 11-current. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Fri Mar 7 17:11:02 UTC 2014 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=187264 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/187264: commit references a PR
Date: Sat,  5 Apr 2014 20:26:20 +0000 (UTC)

 Author: jilles
 Date: Sat Apr  5 20:26:17 2014
 New Revision: 264172
 URL: http://svnweb.freebsd.org/changeset/base/264172
 
 Log:
   MFC r262872: fts: Don't abort if an empty pathname is given.
   
   Make fts_open(3) treat an empty pathname like any other pathname that cannot
   be lstatted because of [ENOENT].
   
   It is rather confusing if  rm -rf file1 "" file2  does not remove file1 and
   file2.
   
   PR:		bin/187264
 
 Modified:
   stable/10/lib/libc/gen/fts.c
 Directory Properties:
   stable/10/   (props changed)
 
 Modified: stable/10/lib/libc/gen/fts.c
 ==============================================================================
 --- stable/10/lib/libc/gen/fts.c	Sat Apr  5 20:11:40 2014	(r264171)
 +++ stable/10/lib/libc/gen/fts.c	Sat Apr  5 20:26:17 2014	(r264172)
 @@ -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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
