[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Re: [PATCH]: libevent/dns DNS_ERR_NOANSWERS
One more cornercase - reply that has no answers at all should be
treated as NODATA too. It is not malformed message.
--
WBRBW, Leonid Evdokimov
xmpp:leon@xxxxxxxxxxxx && http://darkk.net.ru
tel:+79816800702 && tel:+79050965222
From 1cd900a52536fb5294f6c13fa759730ea73574a6 Mon Sep 17 00:00:00 2001
From: Leonid Evdokimov <leon@xxxxxxxxxxxx>
Date: Wed, 19 Oct 2011 22:38:37 +0400
Subject: [PATCH 5/6] Empty DNS reply with OK status is another way to say
NODATA.
Sometimes DNS reply has nothing but query section. It does not look like
error, so it should be treated as NODATA with TTL=0 as soon as there is
no SOA record to deduce negative TTL from.
---
evdns.c | 2 +-
test/regress_dns.c | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/evdns.c b/evdns.c
index 5c02488..4e736d0 100644
--- a/evdns.c
+++ b/evdns.c
@@ -1046,7 +1046,7 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) {
*/
TEST_NAME;
j += 4;
- if (j >= length) goto err;
+ if (j > length) goto err;
}
if (!name_matches)
diff --git a/test/regress_dns.c b/test/regress_dns.c
index e84513e..2b28fc5 100644
--- a/test/regress_dns.c
+++ b/test/regress_dns.c
@@ -497,6 +497,7 @@ static struct regress_dns_server_table search_table[] = {
{ "host2.c.example.com", "err", "3", 0 },
{ "hostn.a.example.com", "errsoa", "0", 0 },
{ "hostn.b.example.com", "errsoa", "3", 0 },
+ { "hostn.c.example.com", "err", "0", 0 },
{ "host", "err", "3", 0 },
{ "host2", "err", "3", 0 },
@@ -513,7 +514,7 @@ dns_search_test(void *arg)
ev_uint16_t portnum = 0;
char buf[64];
- struct generic_dns_callback_result r[7];
+ struct generic_dns_callback_result r[8];
tt_assert(regress_dnsserver(base, &portnum, search_table));
evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
@@ -535,6 +536,7 @@ dns_search_test(void *arg)
evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r[4]);
evdns_base_resolve_ipv4(dns, "hostn.a.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[5]);
evdns_base_resolve_ipv4(dns, "hostn.b.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[6]);
+ evdns_base_resolve_ipv4(dns, "hostn.c.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[7]);
event_base_dispatch(base);
@@ -551,6 +553,8 @@ dns_search_test(void *arg)
tt_int_op(r[5].ttl, ==, 42);
tt_int_op(r[6].result, ==, DNS_ERR_NOTEXIST);
tt_int_op(r[6].ttl, ==, 42);
+ tt_int_op(r[7].result, ==, DNS_ERR_NODATA);
+ tt_int_op(r[7].ttl, ==, 0);
end:
if (dns)
--
1.7.5.4