[Toybox] xargs with blank input

ibid.ag at gmail.com ibid.ag at gmail.com
Wed Oct 16 19:11:23 PDT 2013


On Wed, Oct 16, 2013 at 03:16:47PM -0400, William Haddon wrote:
> How exactly should this behave? I haven't been able to decipher what
> POSIX has to say about the subject. The GNU version executes the
POSIX 2008 (I looked at the old tarball of docs...) says:

"shall construct a command line consisting of the utility and argument
operands specified followed by as many arguments read in sequence from
standard input as fit in length and number constraints specified by
the options."
I read this as "Must in all cases construct the command line", since
there's no note about blank input behaving differently.

> command with no arguments, so that "xargs" with blank input is
> equivalent to "echo" and "xargs ls" with blank input is equivalent
> to "ls". Toybox currently appears to do nothing, but actually forks
> a child process which silently seg-faults as a result of calling
> xexec() with argv[0] == NULL. Patching toybox to implement the GNU
> behavior fixes a lot of scripts on my test system that broke when I
> switched the xargs implementation from busybox to toybox, including
> the
> Linux build scripts. I included the patch below, but I haven't
> tested it with all the numerous options that are available to xargs.
> I'm still investigating whether this toybox behavior is the only
> factor contributing to behavior I observed.
> 
> William Haddon
> 
> diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c
> index e1611ec..6238af8 100644
> --- a/toys/posix/xargs.c
> +++ b/toys/posix/xargs.c
> @@ -160,17 +160,16 @@ void xargs_main(void)
>      if (data && !TT.entries) error_exit("argument too long");
>      out = xzalloc((entries+TT.entries+1)*sizeof(char *));
> 
> -    if (dlist) {
> -      struct double_list *dtemp;
> +    struct double_list *dtemp;
> 
> -      // Fill out command line to exec
> -      memcpy(out, toys.optargs, entries*sizeof(char *));
> -      TT.entries = 0;
> -      TT.bytes = bytes;
> +    // Fill out command line to exec
> +    memcpy(out, toys.optargs, entries*sizeof(char *));
> +    TT.entries = 0;
> +    TT.bytes = bytes;
> +    if (dlist)
>        dlist->prev->next = 0;
> -      for (dtemp = dlist; dtemp; dtemp = dtemp->next)
> -        handle_entries(dtemp->data, out+entries);
> -    }
> +    for (dtemp = dlist; dtemp; dtemp = dtemp->next)
> +      handle_entries(dtemp->data, out+entries);
>      pid_t pid=fork();
>      if (!pid) {
>        xclose(0);
I thought I saw an issue with brace placement, but I didn't...

Thanks,
Isaac Dunham

 1381975883.0


More information about the Toybox mailing list