]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add test for delegdb dump with very long name
authorColin Vidal <colin@isc.org>
Fri, 5 Jun 2026 09:55:07 +0000 (11:55 +0200)
committerColin Vidal <colin@isc.org>
Fri, 12 Jun 2026 13:45:22 +0000 (15:45 +0200)
Add a delegdb test which dump a database which contains a very long name
(using DNS master file format with escape sequence as defined per RFC
1035). This ensure that the delegdb uses large enough internal buffers
to load the names in DB and generate the dump. If this is not the case,
the test crashes on a build with address sanatizer enabled.

tests/dns/deleg_test.c

index 28b789a2f1c720330bba79f291209e3a8b7fa43d..8c673098fa361bf31555e91b5ca0e002dac5fb9c 100644 (file)
@@ -165,7 +165,9 @@ dumpdb(dns_delegdb_t *db, bool expired, const char *expected) {
        REQUIRE(fp != NULL);
        REQUIRE(fread(buffer, sizeof(buffer) - 1, 1, fp) == 0);
 
-       assert_string_equal(expected, buffer);
+       if (expected != NULL) {
+               assert_string_equal(expected, buffer);
+       }
 
        REQUIRE(fclose(fp) == 0);
        REQUIRE(unlink(filename) == 0);
@@ -704,11 +706,69 @@ cleanuptests(ISC_ATTR_UNUSED void *arg) {
        shutdowntest(&db);
 }
 
+static void
+longnametests(ISC_ATTR_UNUSED void *arg) {
+       dns_delegdb_t *db = NULL;
+       dns_deleg_t *deleg = NULL;
+       dns_delegset_t *delegset = NULL;
+
+       dns_delegdb_create(&db);
+       assert_non_null(db);
+
+       dns_delegset_allocset(db, &delegset);
+       dns_delegset_allocdeleg(delegset, DNS_DELEGTYPE_DELEG_NAMES, &deleg);
+       addnamedeleg("ns."
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037."
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037."
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+                    "\037\037\037\037\037.",
+                    delegset, deleg, dns_delegset_addns);
+       writedb(db,
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037."
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037."
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037\037\037\037\037\037\037\037\037\037"
+               "\037\037\037\037\037.",
+               10, &delegset, true);
+
+       /*
+        * `dns_name_totext()` doesn't seems to apply the master zone escape
+        * format, so the actual output wouldn't be the same. But the point of
+        * the test is that we can run the dump code without overflow (with
+        * address sanatizer enabled).
+        */
+       dumpdb(db, false, NULL);
+
+       shutdowntest(&db);
+}
+
 ISC_RUN_TEST_IMPL(dns_deleg_basictests) { rundelegtest(basictests); }
 ISC_RUN_TEST_IMPL(dns_deleg_ttl0tests) { rundelegtest(ttl0tests); }
 ISC_RUN_TEST_IMPL(dns_deleg_noexacttests) { rundelegtest(noexacttests); }
 ISC_RUN_TEST_IMPL(dns_deleg_deletetests) { rundelegtest(deletetests); }
 ISC_RUN_TEST_IMPL(dns_deleg_cleanuptests) { rundelegtest(cleanuptests); }
+ISC_RUN_TEST_IMPL(dns_deleg_longnametests) { rundelegtest(longnametests); }
 
 ISC_TEST_LIST_START
 ISC_TEST_ENTRY(dns_deleg_basictests)
@@ -716,6 +776,7 @@ ISC_TEST_ENTRY(dns_deleg_ttl0tests)
 ISC_TEST_ENTRY(dns_deleg_noexacttests)
 ISC_TEST_ENTRY(dns_deleg_deletetests)
 ISC_TEST_ENTRY(dns_deleg_cleanuptests)
+ISC_TEST_ENTRY(dns_deleg_longnametests)
 ISC_TEST_LIST_END
 
 ISC_TEST_MAIN