busybox/testsuite/xargs.tests
Ron Yorston 1ff7002b1d 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>
2020-01-29 14:39:13 +01:00

54 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Copyright 2008 by Denys Vlasenko
# Licensed under GPLv2, see file LICENSE in this source tree.
. ./testing.sh
# testing "test name" "command" "expected result" "file input" "stdin"
testing "xargs -E _ stops on underscore" \
"xargs -E _" \
"a\n" \
"" "a\n_\nb\n"
testing "xargs -E ''" \
"xargs -E ''" \
"a _ b\n" \
"" "a\n_\nb\n"
testing "xargs -e without param" \
"xargs -e" \
"a _ b\n" \
"" "a\n_\nb\n"
testing "xargs does not stop on underscore ('new' GNU behavior)" \
"xargs" \
"a _ b\n" \
"" "a\n_\nb\n"
testing "xargs -s7 can take one-char input" \
"xargs -s7 echo" \
"a\n" \
"" "a\n"
testing "xargs -sNUM test 1" \
"xargs -ts25 echo 2>&1 >/dev/null" \
"echo 1 2 3 4 5 6 7 8 9 0\n""echo 1 2 3 4 5 6 7 8 9\n""echo 00\n" \
"" "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 00\n"
testing "xargs -sNUM test 2" \
"xargs -ts25 echo 1 2>&1 >/dev/null" \
"echo 1 2 3 4 5 6 7 8 9 0\n""echo 1 2 3 4 5 6 7 8 9\n""echo 1 00\n" \
"" "2 3 4 5 6 7 8 9 0 2 3 4 5 6 7 8 9 00\n"
# see that we don't get "argument line too long",
# but do see the last word, 99999, instead
optional FEATURE_XARGS_SUPPORT_QUOTES
testing "xargs argument line too long" \
"seq 10000 99999 | sed -e 's/^/\"/' -e 's/$/\"/' | xargs echo | grep -o 99999; echo \$?" \
"99999\n0\n" \
"" ""
SKIP=
exit $FAILCOUNT