mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
getaddrinfo: Get rid of alloca
Use a scratch_buffer rather than alloca to avoid potential stack overflow.
This commit is contained in:
parent
3d6fcf1bd7
commit
955a47a4bf
1 changed files with 9 additions and 15 deletions
|
@ -2404,22 +2404,17 @@ getaddrinfo (const char *name, const char *service,
|
||||||
struct addrinfo *q;
|
struct addrinfo *q;
|
||||||
struct addrinfo *last = NULL;
|
struct addrinfo *last = NULL;
|
||||||
char *canonname = NULL;
|
char *canonname = NULL;
|
||||||
bool malloc_results;
|
struct scratch_buffer buf;
|
||||||
size_t alloc_size = nresults * (sizeof (*results) + sizeof (size_t));
|
scratch_buffer_init (&buf);
|
||||||
|
|
||||||
malloc_results
|
if (!scratch_buffer_set_array_size (&buf, nresults,
|
||||||
= !__libc_use_alloca (alloc_size);
|
sizeof (*results) + sizeof (size_t)))
|
||||||
if (malloc_results)
|
|
||||||
{
|
{
|
||||||
results = malloc (alloc_size);
|
__free_in6ai (in6ai);
|
||||||
if (results == NULL)
|
return EAI_MEMORY;
|
||||||
{
|
|
||||||
__free_in6ai (in6ai);
|
|
||||||
return EAI_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
results = buf.data;
|
||||||
results = alloca (alloc_size);
|
|
||||||
order = (size_t *) (results + nresults);
|
order = (size_t *) (results + nresults);
|
||||||
|
|
||||||
/* Now we definitely need the interface information. */
|
/* Now we definitely need the interface information. */
|
||||||
|
@ -2590,8 +2585,7 @@ getaddrinfo (const char *name, const char *service,
|
||||||
/* Fill in the canonical name into the new first entry. */
|
/* Fill in the canonical name into the new first entry. */
|
||||||
p->ai_canonname = canonname;
|
p->ai_canonname = canonname;
|
||||||
|
|
||||||
if (malloc_results)
|
scratch_buffer_free (&buf);
|
||||||
free (results);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__free_in6ai (in6ai);
|
__free_in6ai (in6ai);
|
||||||
|
|
Loading…
Add table
Reference in a new issue