An Android engineer complained that they were seeing this when not
running as root:

  $ adb shell ls
  ls: ./postinstall: Invalid argument
  ls: ./init: Permission denied
  ls: ./data_mirror: Invalid argument
  ls: ./init.environ.rc: Invalid argument
  ls: ./metadata: Invalid argument
  acct
  adb_keys
  apex

>From strace, it was here:

  newfstatat(4, "adb_keys", 0x7fc67eca88, AT_SYMLINK_NOFOLLOW) = -1
EACCES (Permission denied)
  readlinkat(4, "adb_keys", 0x5e843c7720, 4095) = -1 EINVAL (Invalid argument)

So stop looking at st.st_mode (and then deciding to do a readlinkat())
if we didn't actually successfully stat().
---
 lib/dirtree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
From 0b2ab008b78335d4a4616d4b105d24b7667309e3 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 13 Dec 2019 16:15:26 -0800
Subject: [PATCH] dirtree.c: avoid spurious EINVAL warnings.

An Android engineer complained that they were seeing this when not
running as root:

  $ adb shell ls
  ls: ./postinstall: Invalid argument
  ls: ./init: Permission denied
  ls: ./data_mirror: Invalid argument
  ls: ./init.environ.rc: Invalid argument
  ls: ./metadata: Invalid argument
  acct
  adb_keys
  apex

From strace, it was here:

  newfstatat(4, "adb_keys", 0x7fc67eca88, AT_SYMLINK_NOFOLLOW) = -1 EACCES (Permission denied)
  readlinkat(4, "adb_keys", 0x5e843c7720, 4095) = -1 EINVAL (Invalid argument)

So stop looking at st.st_mode (and then deciding to do a readlinkat())
if we didn't actually successfully stat().
---
 lib/dirtree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/dirtree.c b/lib/dirtree.c
index 9917a815..f4cc620d 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -44,7 +44,7 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags)
         else goto error;
       }
     }
-    if (S_ISLNK(st.st_mode)) {
+    if (!statless && S_ISLNK(st.st_mode)) {
       if (0>(linklen = readlinkat(fd, name, libbuf, 4095))) goto error;
       libbuf[linklen++]=0;
     }
-- 
2.24.1.735.g03f4e72817-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to