From 08b5330e2bbdfe5b79e7571c3bf242c7befe96bd Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 13 Dec 2019 16:15:26 -0800 Subject: 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; } -- cgit v1.2.3