summaryrefslogtreecommitdiffstats
path: root/lib/libc/asr/getaddrinfo_async.c
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2012-07-10 09:20:51 +0000
committereric <eric@openbsd.org>2012-07-10 09:20:51 +0000
commit48756ee85dedd6f721ebcc181822375f06c4e19d (patch)
tree5dbb0f5b92af7b616c5e92a886483705bd480a60 /lib/libc/asr/getaddrinfo_async.c
parentset { ... } -> set ( ... ) (diff)
downloadwireguard-openbsd-48756ee85dedd6f721ebcc181822375f06c4e19d.tar.xz
wireguard-openbsd-48756ee85dedd6f721ebcc181822375f06c4e19d.zip
Better handling of servname in getaddrinfo_async. Do not necessarily
fail if there is no entry for a given protocol. Fix issue reported by early testers.
Diffstat (limited to 'lib/libc/asr/getaddrinfo_async.c')
-rw-r--r--lib/libc/asr/getaddrinfo_async.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c
index 180dffc3b15..797fb053aac 100644
--- a/lib/libc/asr/getaddrinfo_async.c
+++ b/lib/libc/asr/getaddrinfo_async.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getaddrinfo_async.c,v 1.2 2012/04/25 20:28:25 eric Exp $ */
+/* $OpenBSD: getaddrinfo_async.c,v 1.3 2012/07/10 09:20:51 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -184,16 +184,17 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar)
break;
}
- if (as->as.ai.servname) {
- as->as.ai.port_udp = get_port(as->as.ai.servname,
- "udp", as->as.ai.hints.ai_flags & AI_NUMERICSERV);
- as->as.ai.port_tcp = get_port(as->as.ai.servname,
- "tcp", as->as.ai.hints.ai_flags & AI_NUMERICSERV);
- if (as->as.ai.port_tcp < 0 || as->as.ai.port_udp < 0) {
- ar->ar_h_errno = NO_RECOVERY;
- ar->ar_gai_errno = EAI_SERVICE;
- break;
- }
+ if (ai->ai_protocol == 0 || ai->ai_protocol == IPPROTO_UDP)
+ as->as.ai.port_udp = get_port(as->as.ai.servname, "udp",
+ as->as.ai.hints.ai_flags & AI_NUMERICSERV);
+ if (ai->ai_protocol == 0 || ai->ai_protocol == IPPROTO_TCP)
+ as->as.ai.port_tcp = get_port(as->as.ai.servname, "tcp",
+ as->as.ai.hints.ai_flags & AI_NUMERICSERV);
+ if (as->as.ai.port_tcp == -2 || as->as.ai.port_udp == -2 ||
+ (as->as.ai.port_tcp == -1 && as->as.ai.port_udp == -1)) {
+ ar->ar_h_errno = NO_RECOVERY;
+ ar->ar_gai_errno = EAI_SERVICE;
+ break;
}
/* If hostname is NULL, use local address */
@@ -465,6 +466,10 @@ add_sockaddr(struct async *as, struct sockaddr *sa, const char *cname)
else
port = 0;
+ /* servname specified, but not defined for this protocol */
+ if (port == -1)
+ continue;
+
ai = calloc(1, sizeof(*ai) + sa->sa_len);
if (ai == NULL)
return (EAI_MEMORY);