]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Test dns_name_fromregion
authorMark Andrews <marka@isc.org>
Tue, 23 Apr 2024 03:34:56 +0000 (13:34 +1000)
committerMark Andrews <marka@isc.org>
Wed, 24 Apr 2024 02:22:46 +0000 (12:22 +1000)
with a large source region and a large target buffer, both
larger than DNS_NAME_MAXWIRE.

(cherry picked from commit 254ba1b051bdc4f90b8210980ca80450d6d11159)

tests/dns/name_test.c

index 511ee3c8b343813ba29bbe7d8b0ce0db1d601f75..225079fed4f8d9e06983cfed7b20b0401d375d60 100644 (file)
@@ -271,6 +271,32 @@ ISC_RUN_TEST_IMPL(compression) {
        dns_compress_invalidate(&cctx);
 }
 
+ISC_RUN_TEST_IMPL(fromregion) {
+       dns_name_t name;
+       isc_buffer_t b;
+       isc_region_t r;
+       /*
+        * target and source need to be bigger than DNS_NAME_MAXWIRE to
+        * exercise 'len > DNS_NAME_MAXWIRE' test in dns_name_fromwire
+        */
+       unsigned char target[DNS_NAME_MAXWIRE + 10];
+       unsigned char source[DNS_NAME_MAXWIRE + 10] = { '\007', 'e', 'x', 'a',
+                                                       'm',    'p', 'l', 'e' };
+       /*
+        * Extract the fully qualified name at the beginning of 'source'
+        * into 'name' where 'name.ndata' points to the buffer 'target'.
+        */
+       isc_buffer_init(&b, target, sizeof(target));
+       dns_name_init(&name, NULL);
+       dns_name_setbuffer(&name, &b);
+       r.base = source;
+       r.length = sizeof(source);
+       dns_name_fromregion(&name, &r);
+       assert_int_equal(9, name.length);
+       assert_ptr_equal(target, name.ndata);
+       assert_true(dns_name_isabsolute(&name));
+}
+
 /* is trust-anchor-telemetry test */
 ISC_RUN_TEST_IMPL(istat) {
        dns_fixedname_t fixed;
@@ -713,6 +739,7 @@ ISC_RUN_TEST_IMPL(benchmark) {
 ISC_TEST_LIST_START
 ISC_TEST_ENTRY(fullcompare)
 ISC_TEST_ENTRY(compression)
+ISC_TEST_ENTRY(fromregion)
 ISC_TEST_ENTRY(istat)
 ISC_TEST_ENTRY(init)
 ISC_TEST_ENTRY(invalidate)