[Toybox] names_to_pid() and behavior for killall and pidof commands on android

Nicolas Noury nicolas.noury at gmail.com
Mon Jun 8 07:33:34 PDT 2015


Hi,

I was trying toybox in nexus 9 android M preview and saw that killall tries
to kill "all" pid and pidof
whatever_you_type_without_a_slash_at_the_beginning answers with a list
containing all existing pids.
I am not sure if it belongs here or to the android bugtracker.

My findings:

in lib.c line 819
         : !strcmp(basename(cmd), basename(*curname)))

call to basename in both strcmp arguments does not work as expected since
the bionic basename  gives back always the same address for the returned
char*

I was not able to find a reliable source for the expected behavior of
baseline concerning the return buffer address and allocation.

1) should we try to fix it here or is it up to android to fix bionic
basename behavior?

2) if fix should be in toybox,
a quick&dirty fix would be to copy the first basename(cmd) result into cmd,
since it's supposed to be smaller in length and cmd is not reused with the
same value anymore, but it relies on the assumption that buffers are not
overlapping, or that strcpy is able to shift to left without mangling
buffer content. If it needs to be safer, one can always allocate a temp
buffer...

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150608/cd6002ad/attachment.htm>


More information about the Toybox mailing list