From: Mark Andrews Date: Tue, 19 May 2026 00:44:04 +0000 (+1000) Subject: Check that dns_name_fromwire honours the active region X-Git-Tag: v9.21.24~13^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3ed821d68b15fe4e6288e3054397d6bce7e65968;p=thirdparty%2Fbind9.git Check that dns_name_fromwire honours the active region When reading DNS records from the wire the active region of the source buffer is set to the end of the current record. dns_name_fromwire should fail if it attempts to read past this setting. --- diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index dab4bbb4c94..f9a0dcf2e11 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -534,6 +534,32 @@ ISC_RUN_TEST_IMPL(fromregion) { assert_false(dns_name_isabsolute(&name)); } +ISC_RUN_TEST_IMPL(fromwire) { + dns_fixedname_t fixed; + dns_name_t *name = dns_fixedname_initname(&fixed); + isc_buffer_t b; + unsigned char source[] = { 0x03, 'o', 'n', 'e', 0x00, 0x03, + 't', 'w', 'o', 0x00, 0x05, 't', + 'h', 'r', 'e', 'e', 0x00 }; + isc_result_t result; + + isc_buffer_init(&b, source, sizeof(source)); + isc_buffer_add(&b, sizeof(source)); + isc_buffer_setactive(&b, 10); /* names 'one.' and 'two.' */ + + /* + * We should only be able to read two names from the buffer + * as the active region has been set to cover only the first + * two. + */ + result = dns_name_fromwire(name, &b, DNS_DECOMPRESS_NEVER, NULL); + assert_int_equal(result, ISC_R_SUCCESS); + result = dns_name_fromwire(name, &b, DNS_DECOMPRESS_NEVER, NULL); + assert_int_equal(result, ISC_R_SUCCESS); + result = dns_name_fromwire(name, &b, DNS_DECOMPRESS_NEVER, NULL); + assert_int_not_equal(result, ISC_R_SUCCESS); +} + /* is trust-anchor-telemetry test */ ISC_RUN_TEST_IMPL(istat) { dns_fixedname_t fixed; @@ -1015,6 +1041,7 @@ ISC_TEST_ENTRY(fullcompare) ISC_TEST_ENTRY(compression) ISC_TEST_ENTRY(collision) ISC_TEST_ENTRY(fromregion) +ISC_TEST_ENTRY(fromwire) ISC_TEST_ENTRY(istat) ISC_TEST_ENTRY(init) ISC_TEST_ENTRY(invalidate)