public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] sysdeps/posix/getaddrinfo: Return early on invalid address family
@ 2019-11-26 10:27 Florian Weimer
0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2019-11-26 10:27 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 2131 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c1de872c8cdfadb077b4c0a04b1a4bd8c18f3894
commit c1de872c8cdfadb077b4c0a04b1a4bd8c18f3894
Author: Tim Rühsen <tim.ruehsen@gmx.de>
Date: Sun Nov 24 22:01:29 2019 +0100
sysdeps/posix/getaddrinfo: Return early on invalid address family
Check address family before expensive function call (__check_pf).
Diff:
---
sysdeps/posix/getaddrinfo.c | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index afdcdf0..c67c5a9 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -2186,6 +2186,10 @@ getaddrinfo (const char *name, const char *service,
if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
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;
size_t in6ailen = 0;
bool seen_ipv4 = false;
@@ -2244,33 +2248,25 @@ getaddrinfo (const char *name, const char *service,
pservice = NULL;
struct addrinfo **end = &p;
-
unsigned int naddrs = 0;
- if (hints->ai_family == AF_UNSPEC || hints->ai_family == AF_INET
- || 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);
+ struct scratch_buffer tmpbuf;
- if (last_i != 0)
- {
- freeaddrinfo (p);
- __free_in6ai (in6ai);
+ scratch_buffer_init (&tmpbuf);
+ last_i = gaih_inet (name, pservice, hints, end, &naddrs, &tmpbuf);
+ scratch_buffer_free (&tmpbuf);
- return -last_i;
- }
- while (*end)
- {
- end = &((*end)->ai_next);
- ++nresults;
- }
- }
- else
+ if (last_i != 0)
{
+ freeaddrinfo (p);
__free_in6ai (in6ai);
- return EAI_FAMILY;
+
+ return -last_i;
+ }
+
+ while (*end)
+ {
+ end = &((*end)->ai_next);
+ ++nresults;
}
if (naddrs > 1)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-11-26 10:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 10:27 [glibc] sysdeps/posix/getaddrinfo: Return early on invalid address family Florian Weimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).