From 304086cd5abcb4ef47258775aae0209005a43f9c Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 23 Apr 2024 13:34:56 +1000 Subject: [PATCH 1/4] Test dns_name_fromregion 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index 511ee3c8b3..225079fed4 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -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) From a94bfb66f2ec14bc6639d0df4e27a295a04b93f7 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 23 Apr 2024 13:34:56 +1000 Subject: [PATCH 2/4] Extract fully qualified named from source without buffer 'name.ndata' should point to the source. (cherry picked from commit 7d7fc8cb2dd1153e4ecbeb894f3e90e8225ccfdd) --- tests/dns/name_test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index 225079fed4..acd36c9ddf 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -295,6 +295,19 @@ ISC_RUN_TEST_IMPL(fromregion) { assert_int_equal(9, name.length); assert_ptr_equal(target, name.ndata); assert_true(dns_name_isabsolute(&name)); + + /* + * Extract the fully qualified name at the beginning of 'source' + * into 'name' where 'name.ndata' points to the source. + */ + isc_buffer_init(&b, target, sizeof(target)); + dns_name_init(&name, NULL); + r.base = source; + r.length = sizeof(source); + dns_name_fromregion(&name, &r); + assert_int_equal(9, name.length); + assert_ptr_equal(source, name.ndata); + assert_true(dns_name_isabsolute(&name)); } /* is trust-anchor-telemetry test */ From 26b522b54d28ee811ae9fdc7598022d5257845cb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 23 Apr 2024 14:10:39 +1000 Subject: [PATCH 3/4] Extract non absolute name from source The entire source region needs to be consumed for this usage. (cherry picked from commit 7a13fcd601cd61ae79d5822602ef7ffd466a05f0) --- tests/dns/name_test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index acd36c9ddf..fa906606c8 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -308,6 +308,19 @@ ISC_RUN_TEST_IMPL(fromregion) { assert_int_equal(9, name.length); assert_ptr_equal(source, name.ndata); assert_true(dns_name_isabsolute(&name)); + + /* + * Extract the partially qualified name in 'source' into 'name' + * where 'name.ndata' points to the source. + */ + isc_buffer_init(&b, target, sizeof(target)); + dns_name_init(&name, NULL); + r.base = source; + r.length = 8; + dns_name_fromregion(&name, &r); + assert_int_equal(8, name.length); + assert_ptr_equal(source, name.ndata); + assert_false(dns_name_isabsolute(&name)); } /* is trust-anchor-telemetry test */ From 5901065534fe9b4d079f7a9ba68cbba64f17cef4 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 23 Apr 2024 14:16:21 +1000 Subject: [PATCH 4/4] Extract empty name in 'source' into 'name' (cherry picked from commit e6984e5c076d28faf8fba921e0a0c35dde5eac31) --- tests/dns/name_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index fa906606c8..e1b5a79fc2 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -321,6 +321,18 @@ ISC_RUN_TEST_IMPL(fromregion) { assert_int_equal(8, name.length); assert_ptr_equal(source, name.ndata); assert_false(dns_name_isabsolute(&name)); + + /* + * Extract empty name in 'source' into 'name'. + */ + isc_buffer_init(&b, target, sizeof(target)); + dns_name_init(&name, NULL); + r.base = source; + r.length = 0; + dns_name_fromregion(&name, &r); + assert_int_equal(0, name.length); + assert_ptr_equal(source, name.ndata); + assert_false(dns_name_isabsolute(&name)); } /* is trust-anchor-telemetry test */