summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-07-10 09:20:52 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-07-10 09:20:52 +0000
commit970047a6c418a599ffb59b0122ce963e569667ed (patch)
tree7b7accfa8a5cf86b9d33d6d06ba77666a000c650 /lib/libc
parent4026ceb8d1f5fa7a51310bb1ca2925435dfad19a (diff)
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')
-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);