sysdeps/posix/getaddrinfo: Return early on invalid address family

Check address family before expensive function call (__check_pf).
This commit is contained in:
Tim Rühsen 2019-11-24 22:01:29 +01:00 committed by Florian Weimer
parent cceb038ac0
commit c1de872c8c

View File

@ -2186,6 +2186,10 @@ getaddrinfo (const char *name, const char *service,
if ((hints->ai_flags & AI_CANONNAME) && name == NULL) if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
return EAI_BADFLAGS; return EAI_BADFLAGS;
if (hints->ai_family != AF_UNSPEC && hints->ai_family != AF_INET
&& hints->ai_family != AF_INET6)
return EAI_FAMILY;
struct in6addrinfo *in6ai = NULL; struct in6addrinfo *in6ai = NULL;
size_t in6ailen = 0; size_t in6ailen = 0;
bool seen_ipv4 = false; bool seen_ipv4 = false;
@ -2244,33 +2248,25 @@ getaddrinfo (const char *name, const char *service,
pservice = NULL; pservice = NULL;
struct addrinfo **end = &p; struct addrinfo **end = &p;
unsigned int naddrs = 0; unsigned int naddrs = 0;
if (hints->ai_family == AF_UNSPEC || hints->ai_family == AF_INET struct scratch_buffer tmpbuf;
|| hints->ai_family == AF_INET6)
{
struct scratch_buffer tmpbuf;
scratch_buffer_init (&tmpbuf);
last_i = gaih_inet (name, pservice, hints, end, &naddrs, &tmpbuf);
scratch_buffer_free (&tmpbuf);
if (last_i != 0) scratch_buffer_init (&tmpbuf);
{ last_i = gaih_inet (name, pservice, hints, end, &naddrs, &tmpbuf);
freeaddrinfo (p); scratch_buffer_free (&tmpbuf);
__free_in6ai (in6ai);
return -last_i; if (last_i != 0)
}
while (*end)
{
end = &((*end)->ai_next);
++nresults;
}
}
else
{ {
freeaddrinfo (p);
__free_in6ai (in6ai); __free_in6ai (in6ai);
return EAI_FAMILY;
return -last_i;
}
while (*end)
{
end = &((*end)->ai_next);
++nresults;
} }
if (naddrs > 1) if (naddrs > 1)