summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2013-04-03 21:13:51 +0000
committerEric Faurot <eric@cvs.openbsd.org>2013-04-03 21:13:51 +0000
commit6c8bcbe5139c7a32e19f73a0dfb9f0ed534523e1 (patch)
tree9b1c7b1e34c0cca2e30f920a98e34ad1ca3b540e /lib
parent9f8bfd0611023050eb8ad7ccbbe5fe362ee18ba3 (diff)
properly follow the CNAME chain in reverse lookups
spotted by sthen@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/asr/gethostnamadr_async.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/libc/asr/gethostnamadr_async.c b/lib/libc/asr/gethostnamadr_async.c
index e819ea56f6e..f230ab6f9ee 100644
--- a/lib/libc/asr/gethostnamadr_async.c
+++ b/lib/libc/asr/gethostnamadr_async.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gethostnamadr_async.c,v 1.16 2013/04/01 15:49:54 deraadt Exp $ */
+/* $OpenBSD: gethostnamadr_async.c,v 1.17 2013/04/03 21:13:50 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -344,8 +344,10 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar)
* No address found in the dns packet. The blocking version
* reports this as an error.
*/
- if (as->as_type == ASR_GETHOSTBYNAME &&
- h->h.h_addr_list[0] == NULL) {
+ if ((as->as_type == ASR_GETHOSTBYNAME &&
+ h->h.h_addr_list[0] == NULL) ||
+ (as->as_type == ASR_GETHOSTBYADDR &&
+ h->h.h_name == NULL)) {
free(h);
async_set_state(as, ASR_STATE_NEXT_DB);
break;
@@ -462,6 +464,7 @@ hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen)
struct header hdr;
struct query q;
struct rr rr;
+ char dname[MAXDNAME];
if ((h = hostent_alloc(family)) == NULL)
return (NULL);
@@ -470,6 +473,8 @@ hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen)
unpack_header(&p, &hdr);
for (; hdr.qdcount; hdr.qdcount--)
unpack_query(&p, &q);
+ strlcpy(dname, q.q_dname, sizeof(dname));
+
for (; hdr.ancount; hdr.ancount--) {
unpack_rr(&p, &rr);
if (rr.rr_class != C_IN)
@@ -481,14 +486,17 @@ hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen)
if (hostent_add_alias(h, rr.rr_dname, 1) == -1)
goto fail;
} else {
- if (hostent_set_cname(h, rr.rr_dname, 1) == -1)
- goto fail;
+ if (strcasecmp(rr.rr_dname, dname) == 0)
+ strlcpy(dname, rr.rr.cname.cname,
+ sizeof(dname));
}
break;
case T_PTR:
if (reqtype != ASR_GETHOSTBYADDR)
break;
+ if (strcasecmp(rr.rr_dname, dname) != 0)
+ continue;
if (hostent_set_cname(h, rr.rr.ptr.ptrname, 1) == -1)
goto fail;
/* XXX See if we need MULTI_PTRS_ARE_ALIASES */