[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] xargs: fix handling of quoted arguments, closes 11441
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2020-01-29 13:40:43
Message-ID: CAK1hOcMpBN9Xye_qoMMR7xtTqR1qDSRrDaEieA1A-gbf7nsA1A () mail ! gmail ! com
[Download RAW message or body]

On Fri, Jan 24, 2020 at 2:17 PM Ron Yorston <rmy@pobox.com> wrote:
>
> 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@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;


I'm trying to avoid statics.

Applied with moving them to "struct globals".
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic