From b89af5ed5c95ebe0466830d90eedd430593a3584 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 20 Sep 2017 13:53:23 -0700 Subject: 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 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index a4b7229b..70ad0758 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1293,3 +1293,16 @@ void do_lines(int fd, void (*call)(char **pline, long len)) if (fd) fclose(fp); } + +// Returns the number of bytes taken by the environment variables. For use +// when calculating the maximum bytes of environment+argument data that can +// be passed to exec for find(1) and xargs(1). +long environ_bytes() +{ + long bytes = sizeof(char *); + char **ev; + + for (ev = environ; *ev; ev++) + bytes += sizeof(char *) + strlen(*ev) + 1; + return bytes; +} -- cgit v1.2.3