]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Check that dns_name_fromwire honours the active region
authorMark Andrews <marka@isc.org>
Tue, 19 May 2026 00:44:04 +0000 (10:44 +1000)
committerMichał Kępień <michal@isc.org>
Fri, 10 Jul 2026 07:26:46 +0000 (09:26 +0200)
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.

tests/dns/name_test.c

index dab4bbb4c943e2cd8fcf36ba791bb49f7cfbf5da..f9a0dcf2e11062ad535af3c705f5114c56d7739e 100644 (file)
@@ -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)