From: Ondřej Surý Date: Thu, 2 Jul 2026 09:38:40 +0000 (+0200) Subject: Consume the preference before reading the locator in NID/L64/L32 tostruct X-Git-Tag: v9.21.24~33^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aa279bbea7851ae35a11356c091d3228ad0941f;p=thirdparty%2Fbind9.git Consume the preference before reading the locator in NID/L64/L32 tostruct tostruct_nid() and tostruct_l64() read the 16-bit preference with the non-consuming uint16_fromregion() and then memmove()'d the whole remaining region -- still ten octets, still anchored at the preference -- into the eight-octet nid[]/l64[] arrays. That folded the preference into the first two locator octets and stored two octets past the end of the array. tostruct_l32() shares the root cause: it read the 32-bit locator from the same unconsumed offset, so the value was built from the preference plus the first two locator octets. Consume the two preference octets first, matching the sibling tostruct_lp(), and assert the expected framing on the fixed-size types. --- diff --git a/lib/dns/rdata/generic/l32_105.c b/lib/dns/rdata/generic/l32_105.c index 9657711bb83..5f2d8933bb8 100644 --- a/lib/dns/rdata/generic/l32_105.c +++ b/lib/dns/rdata/generic/l32_105.c @@ -156,6 +156,8 @@ tostruct_l32(ARGS_TOSTRUCT) { dns_rdata_toregion(rdata, ®ion); l32->pref = uint16_fromregion(®ion); + isc_region_consume(®ion, 2); + INSIST(region.length == sizeof(l32->l32)); n = uint32_fromregion(®ion); l32->l32.s_addr = htonl(n); return ISC_R_SUCCESS; diff --git a/lib/dns/rdata/generic/l64_106.c b/lib/dns/rdata/generic/l64_106.c index 5e9b42e451b..493264fa553 100644 --- a/lib/dns/rdata/generic/l64_106.c +++ b/lib/dns/rdata/generic/l64_106.c @@ -151,6 +151,8 @@ tostruct_l64(ARGS_TOSTRUCT) { dns_rdata_toregion(rdata, ®ion); l64->pref = uint16_fromregion(®ion); + isc_region_consume(®ion, 2); + INSIST(region.length == sizeof(l64->l64)); memmove(l64->l64, region.base, region.length); return ISC_R_SUCCESS; } diff --git a/lib/dns/rdata/generic/nid_104.c b/lib/dns/rdata/generic/nid_104.c index 80d05330579..275772b9e40 100644 --- a/lib/dns/rdata/generic/nid_104.c +++ b/lib/dns/rdata/generic/nid_104.c @@ -151,6 +151,8 @@ tostruct_nid(ARGS_TOSTRUCT) { dns_rdata_toregion(rdata, ®ion); nid->pref = uint16_fromregion(®ion); + isc_region_consume(®ion, 2); + INSIST(region.length == sizeof(nid->nid)); memmove(nid->nid, region.base, region.length); return ISC_R_SUCCESS; }