[Toybox] misleading ls error output

enh enh at google.com
Wed Oct 28 14:44:58 PDT 2015


On Tue, Oct 27, 2015 at 9:59 PM, Rob Landley <rob at landley.net> wrote:
> On 10/23/2015 09:50 PM, enh wrote:
>> "ls /some-directory-you-can't-access" claims the problem is a bad file
>> descriptor...
>>
>> newfstatat(AT_FDCWD, "/data", {st_mode=S_IFDIR|0771, st_size=4096, ...}, 0) = 0
>> openat(AT_FDCWD, "/data", O_RDONLY)     = -1 EACCES (Permission denied)
>> dup(-1)                                 = -1 EBADF (Bad file descriptor)
>> mprotect(0x7fb3a50000, 4096, PROT_READ|PROT_WRITE) = 0
>> mprotect(0x7fb3a50000, 4096, PROT_READ) = 0
>> write(2, "ls: ", 4ls: )                     = 4
>> write(2, "No /data", 8No /data)                 = 8
>> write(2, ": Bad file descriptor", 21: Bad file descriptor)   = 21
>> write(2, "\n", 1
>> )                       = 1
>
> In its defense, strace said bad file descriptor 3 lines earlier. :)
>
> But yeah, we should catch that before the dup().

works for me:

$ adb shell ls -l /data
ls: /data: Permission denied

> And I should apply the
> O_PATH thing too. Hmmm... Ok, I've made a stab at it, but I don't have
> an xattr test environment setup. Care tel tell me if it works?

yep, that works nicely too. sorry i didn't have time to get round to
doing it myself; i've been swamped with other stuff lately.

$ adb shell ls -laZ /dev
...
drwxr-xr-x  2 root      root         u:object_r:devpts:s0
       0 1969-12-31 16:00 pts
...

$ adb shell strace ls -laZ /dev
...
newfstatat(4, "pts", {st_mode=S_IFDIR|0755, st_size=0, ...},
AT_SYMLINK_NOFOLLOW) = 0
openat(4, "pts", O_RDONLY|O_PATH)       = 5
fgetxattr(5, "security.selinux", 0x55a6965730, 255) = -1 EBADF (Bad
file descriptor)
fcntl(5, F_GETFL)                       = 0x200000 (flags O_RDONLY|O_PATH)
getxattr("/proc/self/fd/5", "security.selinux",
"u:object_r:devpts:s0", 255) = 21
close(5)                                = 0
...

> Thanks,
>
> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.

 1446068698.0


More information about the Toybox mailing list