[Toybox] ls -l broken

enh enh at google.com
Wed Nov 20 14:04:41 PST 2019


this change broke `ls -l` for non-existent arguments:

/tmp/toybox-dirtree$ ./toybox ls -l /asd
b--------T 140728898420758 1964107300 476192747 2935, 304972
1969-12-31 16:00 /asd
/tmp/toybox-dirtree$ git revert 0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea
[master f83f87fa] Revert "Let "find -L -type -l" find dangling symlinks."
 1 file changed, 6 insertions(+), 12 deletions(-)
/tmp/toybox-dirtree$ make
scripts/make.sh
Generate headers from toys/*/*.c...
Library probe...........
Make generated/config.h from .config.
Compile toybox......
/tmp/toybox-dirtree$ ./toybox ls -l /asd
ls: /asd: No such file or directory
/tmp/toybox-dirtree$ ./toybox ls -l /asd
ls: /asd: No such file or directory
/tmp/toybox-dirtree$ ./toybox ls -l /asd
ls: /asd: No such file or directory



commit 0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea
Author: Rob Landley <rob at landley.net>
Date:   Tue Oct 29 10:59:46 2019 -0500

    Let "find -L -type -l" find dangling symlinks.

diff --git a/lib/dirtree.c b/lib/dirtree.c
index df38b257..beaafd59 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -32,12 +32,18 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, cha
r *name, int flags)
   int len = 0, linklen = 0, statless = 0;

   if (name) {
-    // open code this because haven't got node to call dirtree_parentfd() on ye
t
-    int fd = parent ? parent->dirfd : AT_FDCWD;
-
-    if (fstatat(fd, name, &st,AT_SYMLINK_NOFOLLOW*!(flags&DIRTREE_SYMFOLLOW)))
{
-      if (flags&DIRTREE_STATLESS) statless++;
-      else goto error;
+    // open code fd = because haven't got node to call dirtree_parentfd() on ye
t
+    int fd = parent ? parent->dirfd : AT_FDCWD,
+      sym = AT_SYMLINK_NOFOLLOW*!(flags&DIRTREE_SYMFOLLOW);
+
+    // stat dangling symlinks
+    if (fstatat(fd, name, &st, sym)) {
+      if (errno != ENOENT
+        || (!sym && fstatat(fd, name, &st, AT_SYMLINK_NOFOLLOW)))
+      {
+        if (flags&DIRTREE_STATLESS) statless++;
+        else goto error;
+      }
     }
     if (S_ISLNK(st.st_mode)) {
       if (0>(linklen = readlinkat(fd, name, libbuf, 4095))) goto error;


More information about the Toybox mailing list