[PATCH] xargs: fix handling of quoted arguments, closes 11441
Ron Yorston
rmy at pobox.com
Fri Jan 24 13:16:45 UTC 2020
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 301 314 +13
static.state - 1 +1
static.q - 1 +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/0 up/down: 15/0) Total: 15 bytes
Signed-off-by: Ron Yorston <rmy at pobox.com>
---
findutils/xargs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 726315803..d215517af 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -261,8 +261,8 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
#define QUOTE 1
#define BACKSLASH 2
#define SPACE 4
- char q = '\0'; /* quote char */
- char state = NORM;
+ static char q = '\0'; /* quote char */
+ static char state = NORM;
char *s = buf; /* start of the word */
char *p = s + strlen(buf); /* end of the word */
--
2.24.1
More information about the busybox
mailing list