[ldns-users] Various fixes
Vitaly Magerya
vmagerya at gmail.com
Sun Aug 5 18:32:24 UTC 2012
Hi, folks. I've been writing a bind9-host replacement using ldns,
and there's a number of problems with the library I've run into:
1. ldns_resolver_nameservers_randomize (resolver.c) shuffles
_nameservers array, but does not shuffle _rtt array; I think
both arrays should be kept in sync.
2. ldns_dname_cat_clone (dname.c) does not check if the resulting
domain name is too long. I'm not sure if this is by design.
3. ldns_pkt_push_rr (packet.c) does not check for errors, and
always returns true.
I'm attaching a patch to fix these problems (it's rather trivial),
hope you'll find it useful.
-------------- next part --------------
diff --git a/dname.c b/dname.c
--- a/dname.c
+++ b/dname.c
@@ -53,6 +53,9 @@
/* we overwrite the nullbyte of rd1 */
new_size = left_size + ldns_rdf_size(rd2);
+ if (new_size > LDNS_MAX_DOMAINLEN) {
+ return NULL;
+ }
buf = LDNS_XMALLOC(uint8_t, new_size);
if (!buf) {
return NULL;
diff --git a/packet.c b/packet.c
--- a/packet.c
+++ b/packet.c
@@ -649,19 +649,27 @@
{
switch(section) {
case LDNS_SECTION_QUESTION:
- ldns_rr_list_push_rr(ldns_pkt_question(packet), rr);
+ if (!ldns_rr_list_push_rr(ldns_pkt_question(packet), rr)) {
+ return false;
+ }
ldns_pkt_set_qdcount(packet, ldns_pkt_qdcount(packet) + 1);
break;
case LDNS_SECTION_ANSWER:
- ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr);
+ if (!ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr)) {
+ return false;
+ }
ldns_pkt_set_ancount(packet, ldns_pkt_ancount(packet) + 1);
break;
case LDNS_SECTION_AUTHORITY:
- ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr);
+ if (!ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr)) {
+ return false;
+ }
ldns_pkt_set_nscount(packet, ldns_pkt_nscount(packet) + 1);
break;
case LDNS_SECTION_ADDITIONAL:
- ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr);
+ if (!ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr)) {
+ return false;
+ }
ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet) + 1);
break;
case LDNS_SECTION_ANY:
diff --git a/resolver.c b/resolver.c
--- a/resolver.c
+++ b/resolver.c
@@ -1333,17 +1333,22 @@
ldns_resolver_nameservers_randomize(ldns_resolver *r)
{
uint16_t i, j;
- ldns_rdf **ns, *tmp;
+ ldns_rdf **ns, *tmpns;
+ size_t *rtt, tmprtt;
/* should I check for ldns_resolver_random?? */
assert(r != NULL);
ns = ldns_resolver_nameservers(r);
+ rtt = ldns_resolver_rtt(r);
for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
j = ldns_get_random() % ldns_resolver_nameserver_count(r);
- tmp = ns[i];
+ tmpns = ns[i];
ns[i] = ns[j];
- ns[j] = tmp;
+ ns[j] = tmpns;
+ tmprtt = rtt[i];
+ rtt[i] = rtt[j];
+ rtt[j] = tmprtt;
}
ldns_resolver_set_nameservers(r, ns);
}
More information about the ldns-users
mailing list