diff --git a/bin/named/wire_debug.c b/bin/named/wire_debug.c index 9911326b43..3a90ee390b 100644 --- a/bin/named/wire_debug.c +++ b/bin/named/wire_debug.c @@ -124,6 +124,7 @@ resolve_packet(dns_db_t *db, isc_buffer_t *source, isc_buffer_t *target) dns_dbnode_t *node; dns_rdataset_t rdataset; isc_boolean_t authoritative = ISC_TRUE; + isc_region_t r; count = 0; status = 0; @@ -151,6 +152,8 @@ resolve_packet(dns_db_t *db, isc_buffer_t *source, isc_buffer_t *target) */ isc_buffer_init(&tbuf, t, sizeof(t), ISC_BUFFERTYPE_BINARY); dns_name_init(&name, NULL); + isc_buffer_remaining(source, &r); + isc_buffer_setactive(source, r.length); result = dns_name_fromwire(&name, source, &dctx, ISC_FALSE, &tbuf); qtype = getshort(source); qclass = getshort(source); diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index 7155c2af60..76516479d9 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -157,6 +157,7 @@ getquestions(isc_buffer_t *source, dns_namelist_t *section, unsigned int count, unsigned int type, class; dns_name_t *name, *curr; dns_rdatalist_t *rdatalist; + isc_region_t r; ISC_LIST_INIT(*section); while (count > 0) { @@ -167,6 +168,9 @@ getquestions(isc_buffer_t *source, dns_namelist_t *section, unsigned int count, exit(1); } name = &names[ncount++]; + + isc_buffer_remaining(source, &r); + isc_buffer_setactive(source, r.length); (void)getname(name, source, target); for (curr = ISC_LIST_HEAD(*section); curr != NULL; @@ -224,6 +228,8 @@ getsection(isc_buffer_t *source, dns_namelist_t *section, unsigned int count, exit(1); } name = &names[ncount++]; + isc_buffer_remaining(source, &r); + isc_buffer_setactive(source, r.length); (void)getname(name, source, target); for (curr = ISC_LIST_HEAD(*section); curr != NULL; diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index 5b218e0fbd..2e16e0b6db 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -289,7 +289,8 @@ dns_name_compare(dns_name_t *name1, dns_name_t *name2); int dns_name_rdatacompare(dns_name_t *name1, dns_name_t *name2); /* - * Compare two names as if they are part of rdata. + * Compare two names as if they are part of rdata in DNSSEC cononical + * form. * * Requires: * 'name1' is a valid absolute name @@ -430,7 +431,8 @@ dns_result_t dns_name_fromwire(dns_name_t *name, isc_boolean_t downcase, isc_buffer_t *target); /* - * Copy the possibly-compressed name at source into target, decompressing it. + * Copy the possibly-compressed name at source (active region) into target, + * decompressing it. * * Notes: * Decompression policy is controlled by 'dctx'. @@ -451,8 +453,8 @@ dns_result_t dns_name_fromwire(dns_name_t *name, * 'name' is a valid name. * * 'source' is a valid buffer of type ISC_BUFFERTYPE_BINARY, and the - * first byte of the used region should be the first byte of a DNS wire - * format message. + * first byte of the active region should be the first byte of a DNS + * wire * format message. * * 'target' is a valid buffer of type ISC_BUFFERTYPE_BINARY. * diff --git a/lib/dns/name.c b/lib/dns/name.c index 1f8c5e32d5..2b33ddab0f 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1668,7 +1668,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, * rather for correctness. Speed will be addressed in the future. */ - while (current < source->used && !done) { + while (current < source->active && !done) { c = *cdata++; current++; if (hops == 0) @@ -1740,16 +1740,17 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, state = fw_start; break; case fw_bitstring: - if (nrem < c + 1) - return (DNS_R_NOSPACE); - nrem -= c + 1; - nused += c + 1; - *ndata++ = c; if (c == 0) - c = 256; - n = c / 8; - if (c % 8 != 0) + n = 256 / 8; + else + n = c / 8; + if ((c % 8) != 0) n++; + if (nrem < n + 1) + return (DNS_R_NOSPACE); + nrem -= n + 1; + nused += n + 1; + *ndata++ = c; state = fw_copy; break; case fw_newcurrent: