xargs: fix handling of quoted arguments, closes 11441
authorRon Yorston <rmy@pobox.com>
Fri, 24 Jan 2020 13:16:45 +0000 (13:16 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 29 Jan 2020 13:39:13 +0000 (14:39 +0100)
commit1ff7002b1d229c678fdffebec602fb4c54439a31
tree71b5f1f29037301c29e6ce41ddca51da3cd237ce
parent16bcd504a32e6a7bf2015ffb241133f9ead6100b
xargs: fix handling of quoted arguments, closes 11441

As reported in bug 11441 when presented with a large number of quoted
arguments xargs can return 'argument line too long':

   seq 10000 29999 | sed -e 's/^/"/' -e 's/$/"/' | busybox xargs echo

This happens because the variant of process_stdin() which handles quoted
arguments doesn't preserve state between calls.  If the allowed number
of characters is exceeded part way through a quoted argument the next
call to process_stdin() incorrectly treats the terminating quote as a
starting quote, thus quoting all of the argument separators.

function                                             old     new   delta
process_stdin                                        274     303     +29
xargs_main                                           731     745     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 43/0)               Total: 43 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
findutils/xargs.c
testsuite/xargs.tests