This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 1/2] posix: execvpe cleanup


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;
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]