[Toybox] test.c hex/octal bug

Luke Frankart frankart at google.com
Tue Nov 24 15:06:12 PST 2020


I found that `toybox test -w` returned true for a file with 0440 mode bits,
and was able to find failures for other cases (below).

I think the root cause and fix is to use octal 0111 instead of hexadecimal
0x111 on this line:
https://github.com/landley/toybox/blob/master/toys/posix/test.c#L74

Thank you,
Luke


generic_x86_arm:/ # toybox --version
toybox 0.8.3-android
generic_x86_arm:/ # chmod 0440 /data/foo ; ls -l /data/foo ; stat -c "%a %A
%f" /data/foo
-r--r----- 1 root root 0 2020-11-24 16:45 /data/foo
440 -r--r----- 8120
generic_x86_arm:/ # toybox test -w /data/foo ; echo $?
0
generic_x86_arm:/ # chmod 0444 /data/foo ; ls -l /data/foo ; stat -c "%a %A
%f" /data/foo
-r--r--r-- 1 root root 0 2020-11-24 16:45 /data/foo
444 -r--r--r-- 8124
generic_x86_arm:/ # toybox test -x /data/foo ; echo $?
0
generic_x86_arm:/ # toybox test -w /data/foo ; echo $?
0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20201124/020230bf/attachment.htm>


More information about the Toybox mailing list