On Tue, 28 Jun 2016 15:24:43 -0000, Florian Obser wrote:
> There is still a bug:
>
> $ mkdir foo; cd foo; touch bar; rm -rf "" bar; echo $?; ls -la; \
> rm -rf nonexistend bar; echo $?; ls -la
> 0
> total 8
> drwxr-xr-x 2 florian wheel 512 Jun 28 17:20 ./
> drwxrwxrwt 9 root wheel 512 Jun 28 17:20 ../
> -rw-r--r-- 1 florian wheel 0 Jun 28 17:20 bar
> 0
> total 8
> drwxr-xr-x 2 florian wheel 512 Jun 28 17:20 ./
> drwxrwxrwt 9 root wheel 512 Jun 28 17:20 ../
>
> i.e. rm does not continue when it fails on "", this only happens when
> specifying -r (because fts_open fails)
I think this needs to be fixed in fts(3) instead. The following
diff fixes it for me but has only been lightly tested.
- todd
Index: lib/libc/gen/fts.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.53
diff -u -p -u -r1.53 fts.c
--- lib/libc/gen/fts.c 1 Nov 2015 03:45:29 -0000 1.53
+++ lib/libc/gen/fts.c 28 Jun 2016 15:40:28 -0000
@@ -107,12 +107,7 @@ fts_open(char * const *argv, int options
/* Allocate/initialize root(s). */
for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
- if ((len = strlen(*argv)) == 0) {
- errno = ENOENT;
- goto mem3;
- }
-
+ len = strlen(*argv);
if ((p = fts_alloc(sp, *argv, len)) == NULL)
goto mem3;
p->fts_level = FTS_ROOTLEVEL;
@@ -810,6 +805,12 @@ fts_stat(FTS *sp, FTSENT *p, int follow,
/* If user needs stat info, stat buffer already allocated. */
sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+ /* Skip zero-length paths. */
+ if (*path == '\0') {
+ p->fts_errno = ENOENT;
+ goto err;
+ }
/*
* If doing a logical walk, or application requested FTS_FOLLOW, do