This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 1/2] posix: execvpe cleanup
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, libc-alpha at sourceware dot org
- Date: Wed, 27 Jan 2016 14:16:48 -0800
- Subject: Re: [PATCH v2 1/2] posix: execvpe cleanup
- Authentication-results: sourceware.org; auth=none
- References: <1453897925-3643-1-git-send-email-adhemerval dot zanella at linaro dot org> <56A8EDA0 dot 6060406 at cs dot ucla dot edu> <56A92566 dot 4010006 at linaro dot org>
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;
}