|
|
b9ba6d |
diff -rup a/include/alloca.h b/include/alloca.h
|
|
|
b9ba6d |
--- a/include/alloca.h 2012-02-29 13:11:19.439693476 -0700
|
|
|
b9ba6d |
+++ b/include/alloca.h 2012-02-29 13:11:49.832530623 -0700
|
|
|
b9ba6d |
@@ -49,15 +49,24 @@ libc_hidden_proto (__libc_alloca_cutoff)
|
|
|
b9ba6d |
|
|
|
b9ba6d |
#if defined stackinfo_get_sp && defined stackinfo_sub_sp
|
|
|
b9ba6d |
# define alloca_account(size, avar) \
|
|
|
b9ba6d |
- ({ void *old__ = stackinfo_get_sp (); \
|
|
|
b9ba6d |
- void *m__ = __alloca (size); \
|
|
|
b9ba6d |
- avar += stackinfo_sub_sp (old__); \
|
|
|
b9ba6d |
+ ({ void *old__ = stackinfo_get_sp (); \
|
|
|
b9ba6d |
+ void *m__ = __alloca (size); \
|
|
|
b9ba6d |
+ avar += stackinfo_sub_sp (old__); \
|
|
|
b9ba6d |
+ m__; })
|
|
|
b9ba6d |
+# define extend_alloca_account(buf, len, newlen, avar) \
|
|
|
b9ba6d |
+ ({ void *old__ = stackinfo_get_sp (); \
|
|
|
b9ba6d |
+ void *m__ = extend_alloca (buf, len, newlen); \
|
|
|
b9ba6d |
+ avar += stackinfo_sub_sp (old__); \
|
|
|
b9ba6d |
m__; })
|
|
|
b9ba6d |
#else
|
|
|
b9ba6d |
# define alloca_account(size, avar) \
|
|
|
b9ba6d |
- ({ size_t s__ = (size); \
|
|
|
b9ba6d |
- avar += s__; \
|
|
|
b9ba6d |
+ ({ size_t s__ = (size); \
|
|
|
b9ba6d |
+ avar += s__; \
|
|
|
b9ba6d |
__alloca (s__); })
|
|
|
b9ba6d |
+# define extend_alloca_account(buf, len, newlen, avar) \
|
|
|
b9ba6d |
+ ({ size_t s__ = (newlen); \
|
|
|
b9ba6d |
+ avar += s__; \
|
|
|
b9ba6d |
+ extend_alloca (buf, len, s__); })
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
diff -rup a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
|
|
|
b9ba6d |
--- a/sysdeps/posix/getaddrinfo.c 2012-02-29 13:11:19.588692676 -0700
|
|
|
b9ba6d |
+++ b/sysdeps/posix/getaddrinfo.c 2012-02-29 13:12:42.972245862 -0700
|
|
|
b9ba6d |
@@ -278,6 +278,7 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
bool got_ipv6 = false;
|
|
|
b9ba6d |
const char *canon = NULL;
|
|
|
b9ba6d |
const char *orig_name = name;
|
|
|
b9ba6d |
+ size_t alloca_used = 0;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (req->ai_protocol || req->ai_socktype)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
@@ -310,7 +311,7 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
if (tp->name[0])
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
st = (struct gaih_servtuple *)
|
|
|
b9ba6d |
- __alloca (sizeof (struct gaih_servtuple));
|
|
|
b9ba6d |
+ alloca_account (sizeof (struct gaih_servtuple), alloca_used);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if ((rc = gaih_inet_serv (service->name, tp, req, st)))
|
|
|
b9ba6d |
return rc;
|
|
|
b9ba6d |
@@ -334,7 +335,8 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
continue;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
newp = (struct gaih_servtuple *)
|
|
|
b9ba6d |
- __alloca (sizeof (struct gaih_servtuple));
|
|
|
b9ba6d |
+ alloca_account (sizeof (struct gaih_servtuple),
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
@@ -362,7 +364,7 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (req->ai_socktype || req->ai_protocol)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- st = __alloca (sizeof (struct gaih_servtuple));
|
|
|
b9ba6d |
+ st = alloca_account (sizeof (struct gaih_servtuple), alloca_used);
|
|
|
b9ba6d |
st->next = NULL;
|
|
|
b9ba6d |
st->socktype = tp->socktype;
|
|
|
b9ba6d |
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
b9ba6d |
@@ -379,7 +381,8 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
struct gaih_servtuple *newp;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- newp = __alloca (sizeof (struct gaih_servtuple));
|
|
|
b9ba6d |
+ newp = alloca_account (sizeof (struct gaih_servtuple),
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
newp->next = NULL;
|
|
|
b9ba6d |
newp->socktype = tp->socktype;
|
|
|
b9ba6d |
newp->protocol = tp->protocol;
|
|
|
b9ba6d |
@@ -391,10 +394,17 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
+ bool malloc_name = false;
|
|
|
b9ba6d |
+ bool malloc_addrmem = false;
|
|
|
b9ba6d |
+ struct gaih_addrtuple *addrmem = NULL;
|
|
|
b9ba6d |
+ bool malloc_canonbuf = false;
|
|
|
b9ba6d |
+ char *canonbuf = NULL;
|
|
|
b9ba6d |
+ bool malloc_tmpbuf = false;
|
|
|
b9ba6d |
+ char *tmpbuf = NULL;
|
|
|
b9ba6d |
+ int result = 0;
|
|
|
b9ba6d |
if (name != NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- at = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
-
|
|
|
b9ba6d |
+ at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
|
|
|
b9ba6d |
at->family = AF_UNSPEC;
|
|
|
b9ba6d |
at->scopeid = 0;
|
|
|
b9ba6d |
at->next = NULL;
|
|
|
b9ba6d |
@@ -412,6 +422,7 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
rc = __idna_to_ascii_lz (name, &p, idn_flags);
|
|
|
b9ba6d |
if (rc != IDNA_SUCCESS)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
+ /* No need to jump to free_and_return here. */
|
|
|
b9ba6d |
if (rc == IDNA_MALLOC_ERROR)
|
|
|
b9ba6d |
return -EAI_MEMORY;
|
|
|
b9ba6d |
if (rc == IDNA_DLOPEN_ERROR)
|
|
|
b9ba6d |
@@ -421,10 +432,7 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
/* In case the output string is the same as the input string
|
|
|
b9ba6d |
no new string has been allocated. */
|
|
|
b9ba6d |
if (p != name)
|
|
|
b9ba6d |
- {
|
|
|
b9ba6d |
- name = strdupa (p);
|
|
|
b9ba6d |
- free (p);
|
|
|
b9ba6d |
- }
|
|
|
b9ba6d |
+ malloc_name = true;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
|
|
|
b9ba6d |
@@ -441,23 +449,59 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
at->family = AF_INET6;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
- return -EAI_ADDRFAMILY;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_ADDRFAMILY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (req->ai_flags & AI_CANONNAME)
|
|
|
b9ba6d |
canon = name;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else if (at->family == AF_UNSPEC)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- char *namebuf = (char *) name;
|
|
|
b9ba6d |
char *scope_delim = strchr (name, SCOPE_DELIMITER);
|
|
|
b9ba6d |
+ int e;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- if (__builtin_expect (scope_delim != NULL, 0))
|
|
|
b9ba6d |
- {
|
|
|
b9ba6d |
- namebuf = alloca (scope_delim - name + 1);
|
|
|
b9ba6d |
- *((char *) __mempcpy (namebuf, name, scope_delim - name)) = '\0';
|
|
|
b9ba6d |
- }
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ bool malloc_namebuf = false;
|
|
|
b9ba6d |
+ char *namebuf = (char *) name;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (__builtin_expect (scope_delim != NULL, 0))
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ if (malloc_name)
|
|
|
b9ba6d |
+ *scope_delim = '\0';
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ if (__libc_use_alloca (alloca_used
|
|
|
b9ba6d |
+ + scope_delim - name + 1))
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ namebuf = alloca_account (scope_delim - name + 1,
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ *((char *) __mempcpy (namebuf, name,
|
|
|
b9ba6d |
+ scope_delim - name)) = '\0';
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ namebuf = strndup (name, scope_delim - name);
|
|
|
b9ba6d |
+ if (namebuf == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ assert (!malloc_name);
|
|
|
b9ba6d |
+ return -EAI_MEMORY;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ malloc_namebuf = true;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- if (inet_pton (AF_INET6, namebuf, at->addr) > 0)
|
|
|
b9ba6d |
+ e = inet_pton (AF_INET6, namebuf, at->addr);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (malloc_namebuf)
|
|
|
b9ba6d |
+ free (namebuf);
|
|
|
b9ba6d |
+ else if (scope_delim != NULL && malloc_name)
|
|
|
b9ba6d |
+ /* Undo what we did above. */
|
|
|
b9ba6d |
+ *scope_delim = SCOPE_DELIMITER;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ if (e > 0)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
|
|
|
b9ba6d |
at->family = AF_INET6;
|
|
|
b9ba6d |
@@ -468,7 +512,10 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
at->family = AF_INET;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
- return -EAI_ADDRFAMILY;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_ADDRFAMILY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (scope_delim != NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
@@ -490,7 +537,10 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end,
|
|
|
b9ba6d |
10);
|
|
|
b9ba6d |
if (*end != '\0')
|
|
|
b9ba6d |
- return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
@@ -520,59 +570,80 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
int family = req->ai_family;
|
|
|
b9ba6d |
size_t tmpbuflen = 512;
|
|
|
b9ba6d |
- char *tmpbuf = alloca (tmpbuflen);
|
|
|
b9ba6d |
+ assert (tmpbuf == NULL);
|
|
|
b9ba6d |
+ tmpbuf = alloca_account (tmpbuflen, alloca_used);
|
|
|
b9ba6d |
int rc;
|
|
|
b9ba6d |
struct hostent th;
|
|
|
b9ba6d |
struct hostent *h;
|
|
|
b9ba6d |
int herrno;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- simple_again:
|
|
|
b9ba6d |
while (1)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- rc = __gethostbyname2_r (name, family, &th, tmpbuf,
|
|
|
b9ba6d |
+ rc = __gethostbyname2_r (name, AF_INET, &th, tmpbuf,
|
|
|
b9ba6d |
tmpbuflen, &h, &herrno);
|
|
|
b9ba6d |
if (rc != ERANGE || herrno != NETDB_INTERNAL)
|
|
|
b9ba6d |
break;
|
|
|
b9ba6d |
- tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (!malloc_tmpbuf
|
|
|
b9ba6d |
+ && __libc_use_alloca (alloca_used + 2 * tmpbuflen))
|
|
|
b9ba6d |
+ tmpbuf = extend_alloca_account (tmpbuf, tmpbuflen,
|
|
|
b9ba6d |
+ 2 * tmpbuflen,
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ char *newp = realloc (malloc_tmpbuf ? tmpbuf : NULL,
|
|
|
b9ba6d |
+ 2 * tmpbuflen);
|
|
|
b9ba6d |
+ if (newp == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ tmpbuf = newp;
|
|
|
b9ba6d |
+ malloc_tmpbuf = true;
|
|
|
b9ba6d |
+ tmpbuflen = 2 * tmpbuflen;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (rc == 0)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- if (h == NULL)
|
|
|
b9ba6d |
+ if (h != NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- if (req->ai_family == AF_INET6
|
|
|
b9ba6d |
- && (req->ai_flags & AI_V4MAPPED)
|
|
|
b9ba6d |
- && family == AF_INET6)
|
|
|
b9ba6d |
+ int i;
|
|
|
b9ba6d |
+ /* We found data, count the number of addresses. */
|
|
|
b9ba6d |
+ for (i = 0; h->h_addr_list[i]; ++i)
|
|
|
b9ba6d |
+ ;
|
|
|
b9ba6d |
+ if (i > 0 && *pat != NULL)
|
|
|
b9ba6d |
+ --i;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (__libc_use_alloca (alloca_used
|
|
|
b9ba6d |
+ + i * sizeof (struct gaih_addrtuple)))
|
|
|
b9ba6d |
+ addrmem = alloca_account (i * sizeof (struct gaih_addrtuple),
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- /* Try again, this time looking for IPv4
|
|
|
b9ba6d |
- addresses. */
|
|
|
b9ba6d |
- family = AF_INET;
|
|
|
b9ba6d |
- goto simple_again;
|
|
|
b9ba6d |
+ addrmem = malloc (i
|
|
|
b9ba6d |
+ * sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
+ if (addrmem == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
+ malloc_addrmem = true;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
- else
|
|
|
b9ba6d |
- {
|
|
|
b9ba6d |
- /* We found data, now convert it into the list. */
|
|
|
b9ba6d |
- for (int i = 0; h->h_addr_list[i]; ++i)
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ /* Now convert it into the list. */
|
|
|
b9ba6d |
+ struct gaih_addrtuple *addrfree = addrmem;
|
|
|
b9ba6d |
+ for (i = 0; h->h_addr_list[i]; ++i)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
if (*pat == NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- *pat = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
+ *pat = addrfree++;
|
|
|
b9ba6d |
(*pat)->scopeid = 0;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
(*pat)->next = NULL;
|
|
|
b9ba6d |
- (*pat)->family = req->ai_family;
|
|
|
b9ba6d |
- if (family == req->ai_family)
|
|
|
b9ba6d |
+ (*pat)->family = AF_INET;
|
|
|
b9ba6d |
memcpy ((*pat)->addr, h->h_addr_list[i],
|
|
|
b9ba6d |
h->h_length);
|
|
|
b9ba6d |
- else
|
|
|
b9ba6d |
- {
|
|
|
b9ba6d |
- uint32_t *addr = (uint32_t *) (*pat)->addr;
|
|
|
b9ba6d |
- addr[3] = *(uint32_t *) h->h_addr_list[i];
|
|
|
b9ba6d |
- addr[2] = htonl (0xffff);
|
|
|
b9ba6d |
- addr[1] = 0;
|
|
|
b9ba6d |
- addr[0] = 0;
|
|
|
b9ba6d |
- }
|
|
|
b9ba6d |
pat = &((*pat)->next);
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
@@ -582,15 +653,16 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
if (herrno == NETDB_INTERNAL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
__set_h_errno (herrno);
|
|
|
b9ba6d |
- return -EAI_SYSTEM;
|
|
|
b9ba6d |
- }
|
|
|
b9ba6d |
- if (herrno == TRY_AGAIN)
|
|
|
b9ba6d |
- {
|
|
|
b9ba6d |
- return -EAI_AGAIN;
|
|
|
b9ba6d |
+ result = -EAI_SYSTEM;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
+ else if (herrno == TRY_AGAIN)
|
|
|
b9ba6d |
+ result = -EAI_AGAIN;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
/* We made requests but they turned out no data.
|
|
|
b9ba6d |
The name is known, though. */
|
|
|
b9ba6d |
- return GAIH_OKIFUNSPEC | -EAI_NODATA;
|
|
|
b9ba6d |
+ result = GAIH_OKIFUNSPEC | -EAI_NODATA;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
goto process_list;
|
|
|
b9ba6d |
@@ -613,21 +685,56 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
|
|
|
b9ba6d |
char *addrs = air->addrs;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
+ if (__libc_use_alloca (alloca_used
|
|
|
b9ba6d |
+ + air->naddrs * sizeof (struct gaih_addrtuple)))
|
|
|
b9ba6d |
+ addrmem = alloca_account (air->naddrs
|
|
|
b9ba6d |
+ * sizeof (struct gaih_addrtuple),
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ addrmem = malloc (air->naddrs
|
|
|
b9ba6d |
+ * sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
+ if (addrmem == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ malloc_addrmem = true;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ struct gaih_addrtuple *addrfree = addrmem;
|
|
|
b9ba6d |
for (int i = 0; i < air->naddrs; ++i)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
socklen_t size = (air->family[i] == AF_INET
|
|
|
b9ba6d |
? INADDRSZ : IN6ADDRSZ);
|
|
|
b9ba6d |
if (*pat == NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
- *pat = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
+ *pat = addrfree++;
|
|
|
b9ba6d |
(*pat)->scopeid = 0;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
uint32_t *pataddr = (*pat)->addr;
|
|
|
b9ba6d |
(*pat)->next = NULL;
|
|
|
b9ba6d |
if (added_canon || air->canon == NULL)
|
|
|
b9ba6d |
(*pat)->name = NULL;
|
|
|
b9ba6d |
- else
|
|
|
b9ba6d |
- canon = (*pat)->name = strdupa (air->canon);
|
|
|
b9ba6d |
+ else if (canonbuf == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ size_t canonlen = strlen (air->canon) + 1;
|
|
|
b9ba6d |
+ if ((req->ai_flags & AI_CANONIDN) != 0
|
|
|
b9ba6d |
+ && __libc_use_alloca (alloca_used + canonlen))
|
|
|
b9ba6d |
+ canonbuf = alloca_account (canonlen, alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ canonbuf = malloc (canonlen);
|
|
|
b9ba6d |
+ if (canonbuf == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ malloc_canonbuf = true;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ canon = (*pat)->name = memcpy (canonbuf, air->canon,
|
|
|
b9ba6d |
+ canonlen);
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (air->family[i] == AF_INET
|
|
|
b9ba6d |
&& req->ai_family == AF_INET6
|
|
|
b9ba6d |
@@ -657,20 +764,26 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
free (air);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (at->family == AF_UNSPEC)
|
|
|
b9ba6d |
- return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
goto process_list;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else if (err == 0)
|
|
|
b9ba6d |
/* The database contains a negative entry. */
|
|
|
b9ba6d |
- return 0;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
else if (__nss_not_use_nscd_hosts == 0)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
if (herrno == NETDB_INTERNAL && errno == ENOMEM)
|
|
|
b9ba6d |
- return -EAI_MEMORY;
|
|
|
b9ba6d |
- if (herrno == TRY_AGAIN)
|
|
|
b9ba6d |
- return -EAI_AGAIN;
|
|
|
b9ba6d |
- return -EAI_SYSTEM;
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ else if (herrno == TRY_AGAIN)
|
|
|
b9ba6d |
+ result = -EAI_AGAIN;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ result = -EAI_SYSTEM;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
@@ -699,7 +812,19 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
_res.options &= ~RES_USE_INET6;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
size_t tmpbuflen = 1024;
|
|
|
b9ba6d |
- char *tmpbuf = alloca (tmpbuflen);
|
|
|
b9ba6d |
+ malloc_tmpbuf = !__libc_use_alloca (alloca_used + tmpbuflen);
|
|
|
b9ba6d |
+ assert (tmpbuf == NULL);
|
|
|
b9ba6d |
+ if (!malloc_tmpbuf)
|
|
|
b9ba6d |
+ tmpbuf = alloca_account (tmpbuflen, alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ tmpbuf = malloc (tmpbuflen);
|
|
|
b9ba6d |
+ if (tmpbuf == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
|
|
|
b9ba6d |
while (!no_more)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
@@ -728,8 +853,25 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
no_data = herrno == NO_DATA;
|
|
|
b9ba6d |
break;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
- tmpbuf = extend_alloca (tmpbuf,
|
|
|
b9ba6d |
- tmpbuflen, 2 * tmpbuflen);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (!malloc_tmpbuf
|
|
|
b9ba6d |
+ && __libc_use_alloca (alloca_used + 2 * tmpbuflen))
|
|
|
b9ba6d |
+ tmpbuf = extend_alloca_account (tmpbuf, tmpbuflen,
|
|
|
b9ba6d |
+ 2 * tmpbuflen,
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ char *newp = realloc (malloc_tmpbuf ? tmpbuf : NULL,
|
|
|
b9ba6d |
+ 2 * tmpbuflen);
|
|
|
b9ba6d |
+ if (newp == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ tmpbuf = newp;
|
|
|
b9ba6d |
+ malloc_tmpbuf = true;
|
|
|
b9ba6d |
+ tmpbuflen = 2 * tmpbuflen;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (status == NSS_STATUS_SUCCESS)
|
|
|
b9ba6d |
@@ -832,18 +974,40 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
if (cfct != NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
const size_t max_fqdn_len = 256;
|
|
|
b9ba6d |
- char *buf = alloca (max_fqdn_len);
|
|
|
b9ba6d |
+ if ((req->ai_flags & AI_CANONIDN) != 0
|
|
|
b9ba6d |
+ && __libc_use_alloca (alloca_used
|
|
|
b9ba6d |
+ + max_fqdn_len))
|
|
|
b9ba6d |
+ canonbuf = alloca_account (max_fqdn_len,
|
|
|
b9ba6d |
+ alloca_used);
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ canonbuf = malloc (max_fqdn_len);
|
|
|
b9ba6d |
+ if (canonbuf == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ malloc_canonbuf = true;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
char *s;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (DL_CALL_FCT (cfct, (at->name ?: name,
|
|
|
b9ba6d |
- buf, max_fqdn_len,
|
|
|
b9ba6d |
+ canonbuf,
|
|
|
b9ba6d |
+ max_fqdn_len,
|
|
|
b9ba6d |
&s, &rc, &herrno))
|
|
|
b9ba6d |
== NSS_STATUS_SUCCESS)
|
|
|
b9ba6d |
canon = s;
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
- /* Set to name now to avoid using
|
|
|
b9ba6d |
- gethostbyaddr. */
|
|
|
b9ba6d |
- canon = name;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ /* Set to name now to avoid using
|
|
|
b9ba6d |
+ gethostbyaddr. */
|
|
|
b9ba6d |
+ if (malloc_canonbuf)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ free (canonbuf);
|
|
|
b9ba6d |
+ malloc_canonbuf = false;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ canon = name;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
status = NSS_STATUS_SUCCESS;
|
|
|
b9ba6d |
@@ -878,22 +1042,27 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* If both requests timed out report this. */
|
|
|
b9ba6d |
if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
|
|
|
b9ba6d |
- return -EAI_AGAIN;
|
|
|
b9ba6d |
+ result = -EAI_AGAIN;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ /* We made requests but they turned out no data. The name
|
|
|
b9ba6d |
+ is known, though. */
|
|
|
b9ba6d |
+ result = GAIH_OKIFUNSPEC | -EAI_NODATA;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- /* We made requests but they turned out no data. The name
|
|
|
b9ba6d |
- is known, though. */
|
|
|
b9ba6d |
- return GAIH_OKIFUNSPEC | -EAI_NODATA;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
process_list:
|
|
|
b9ba6d |
if (at->family == AF_UNSPEC)
|
|
|
b9ba6d |
- return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ result = GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
struct gaih_addrtuple *atr;
|
|
|
b9ba6d |
- atr = at = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
+ atr = at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
|
|
|
b9ba6d |
memset (at, '\0', sizeof (struct gaih_addrtuple));
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (req->ai_family == AF_UNSPEC)
|
|
|
b9ba6d |
@@ -932,6 +1101,9 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
/* Only the first entry gets the canonical name. */
|
|
|
b9ba6d |
if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
+ char *tmpbuf2 = NULL;
|
|
|
b9ba6d |
+ bool malloc_tmpbuf2 = false;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
if (canon == NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* If the canonical name cannot be determined, use
|
|
|
b9ba6d |
@@ -952,11 +1124,16 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags);
|
|
|
b9ba6d |
if (rc != IDNA_SUCCESS)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
+ if (malloc_tmpbuf2)
|
|
|
b9ba6d |
+ free (tmpbuf2);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
if (rc == IDNA_MALLOC_ERROR)
|
|
|
b9ba6d |
- return -EAI_MEMORY;
|
|
|
b9ba6d |
- if (rc == IDNA_DLOPEN_ERROR)
|
|
|
b9ba6d |
- return -EAI_SYSTEM;
|
|
|
b9ba6d |
- return -EAI_IDN_ENCODE;
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ else if (rc == IDNA_DLOPEN_ERROR)
|
|
|
b9ba6d |
+ result = -EAI_SYSTEM;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ result = -EAI_IDN_ENCODE;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
/* In case the output string is the same as the input
|
|
|
b9ba6d |
string no new string has been allocated and we
|
|
|
b9ba6d |
@@ -970,10 +1147,25 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
#ifdef HAVE_LIBIDN
|
|
|
b9ba6d |
make_copy:
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
- canon = strdup (canon);
|
|
|
b9ba6d |
- if (canon == NULL)
|
|
|
b9ba6d |
- return -EAI_MEMORY;
|
|
|
b9ba6d |
+ if (malloc_canonbuf)
|
|
|
b9ba6d |
+ /* We already allocated the string using malloc. */
|
|
|
b9ba6d |
+ malloc_canonbuf = false;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ canon = strdup (canon);
|
|
|
b9ba6d |
+ if (canon == NULL)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ if (malloc_tmpbuf2)
|
|
|
b9ba6d |
+ free (tmpbuf2);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ if (malloc_tmpbuf2)
|
|
|
b9ba6d |
+ free (tmpbuf2);
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
family = at2->family;
|
|
|
b9ba6d |
@@ -999,7 +1191,8 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
if (ai == NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
free ((char *) canon);
|
|
|
b9ba6d |
- return -EAI_MEMORY;
|
|
|
b9ba6d |
+ result = -EAI_MEMORY;
|
|
|
b9ba6d |
+ goto free_and_return;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
ai->ai_flags = req->ai_flags;
|
|
|
b9ba6d |
@@ -1052,7 +1245,18 @@ gaih_inet (const char *name, const struc
|
|
|
b9ba6d |
at2 = at2->next;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
- return 0;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ free_and_return:
|
|
|
b9ba6d |
+ if (malloc_name)
|
|
|
b9ba6d |
+ free ((char *) name);
|
|
|
b9ba6d |
+ if (malloc_addrmem)
|
|
|
b9ba6d |
+ free (addrmem);
|
|
|
b9ba6d |
+ if (malloc_canonbuf)
|
|
|
b9ba6d |
+ free (canonbuf);
|
|
|
b9ba6d |
+ if (malloc_tmpbuf)
|
|
|
b9ba6d |
+ free (tmpbuf);
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ return result;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
|