[PATCH v2 1/2] posix: execvpe cleanup

Paul Eggert eggert@cs.ucla.edu
Wed Jan 27 22:16:00 GMT 2016


On 01/27/2016 12:15 PM, Adhemerval Zanella wrote:
>    int argc = 0;
>    do
>      if ((argc+1) == NCARGS)
>        {
>          errno = E2BIG;
>          return;
>        }
>    while (argv[argc++] != NULL);

Change that to something like the following (this is pseudocode):

     int argc = 0;
     int limit = min (NCARGS, allocacutoff / sizeof (char *));
     while (argv[argc++] != NULL)
       if (limit <= argc)
         {
            errno = E2BIG;
            return;
         }

That way, you won't need the following snippet:

>
>    /* Linux accepts a very large argument number (INT_MAX to fit on a signed
>       32-bit integer).  To limit stack allocation we set it to a lower
>       bound.  */
>    if (!__libc_alloca_cutoff (argc * sizeof (char*)))
>      {
>        errno = E2BIG;
>        return;
>      }



More information about the Libc-alpha mailing list