[Toybox] [landley/toybox] xargs: exec ... Argument list too long (#40)

enh enh at google.com
Wed Sep 20 13:59:05 PDT 2017


this bug was reported again internally this week (within a day of a
year and a month). patch for xargs attached.



Subject: [PATCH] Fix xargs to obey POSIX's ARG_MAX restrictions.

This avoids "xargs: exec echo: Argument list too long" errors in practice.

find(1) needs to be fixed too, but that's a bit more complicated and a working
xargs provides a workaround.

Bug: http://b/65818597
Test: find /proc | strace -f -e execve ./toybox xargs echo > /dev/null
---
 lib/lib.c          | 13 +++++++++++++
 lib/lib.h          |  1 +
 toys/posix/xargs.c | 14 +++++++++++++-
 3 files changed, 27 insertions(+), 1 deletion(-)

On Mon, Aug 15, 2016 at 12:06 AM, Rob Landley <rob at landley.net> wrote:
> On 08/13/2016 04:36 PM, enh wrote:
>>>> Oh well, use the sysconf and then file a bug against musl. (Elliott will
>>>> probably notice this, and if not he'll notice the commit.)
>>>
>>> yeah, this is as good a bionic bug reporting forum as any :-)
>>
>> fixed in AOSP. (took a while to kill code in the internal tree making
>> bad assumptions about ARG_MAX...)
>
> I've gotta add the measuring code back to find.
>
> There's also this fun little corner case from susv4's xargs page
>
>> The xargs utility shall limit the command line length such that when
>> the command line is invoked, the combined argument and environment
>> lists (see the exec family of functions in the System Interfaces
>> volume of POSIX.1-2008) shall not exceed {ARG_MAX}-2048 bytes.
>> Within this constraint, if neither the -n nor the -s option is
>> specified, the default command line length shall be at least
>> {LINE_MAX}.
>
> So they want a gratuitous -2048 constant in there. I don't know if this
> is because they're _not_ measuring the space used by the actual argv[]
> and envp[] pointer arrays, or because they're leaving space for the new
> command to add extra environment data to itself, or...?
>
> I'm leaning towards doing another "nuts to your white mice" at posix's
> magic constant here and just actually measuring the real-world things
> they never mention the existence of. Or I could just hardwire a random
> default like they suggest and let people -s specify it if they know what
> they're doing. (Alas, I've run out of weekend...)
>
> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-xargs-to-obey-POSIX-s-ARG_MAX-restrictions.patch
Type: text/x-patch
Size: 3200 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20170920/a7cafe2c/attachment.bin>


More information about the Toybox mailing list