From 4ace37bf7386e73af1d295d206b101c27a9edbad Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 24 Nov 2021 11:03:19 +1100 Subject: [PATCH 1/3] Do not convert ISC_R_NOSPACE to DNS_R_SERVFAIL too early The parsing loop needs to process ISC_R_NOSPACE to properly size the buffer. If result is still ISC_R_NOSPACE at the end of the parsing loop set result to DNS_R_SERVFAIL. (cherry picked from commit 08f1cba096243cd14041731b7ea1ad45e54e87b0) --- lib/dns/sdlz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dns/sdlz.c b/lib/dns/sdlz.c index c8a615a0f3..0b46fb9efd 100644 --- a/lib/dns/sdlz.c +++ b/lib/dns/sdlz.c @@ -1875,7 +1875,6 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, mctx, rdatabuf, &lookup->callbacks); if (result != ISC_R_SUCCESS) { isc_buffer_free(&rdatabuf); - result = DNS_R_SERVFAIL; } if (size >= 65535) { break; @@ -1887,6 +1886,7 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, } while (result == ISC_R_NOSPACE); if (result != ISC_R_SUCCESS) { + result = DNS_R_SERVFAIL; goto failure; } From bf1eaf46611bdbfcc2a6f6f77871eebf8351a629 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 25 Nov 2021 13:16:56 +1100 Subject: [PATCH 2/3] Exercise ISC_R_NOSPACE path in dns_sdlz_putrr Use relative names when adding SOA record and a long domain name to create SOA RR where the wire format is longer than the initial buffer allocation in dns_sdlz_putrr. (cherry picked from commit 6dc524860622277bd24fe17d4a82454b30f5f1b5) --- bin/tests/system/dlzexternal/driver.c | 23 +++++++++---------- bin/tests/system/dlzexternal/ns1/dlzs.conf.in | 5 ++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bin/tests/system/dlzexternal/driver.c b/bin/tests/system/dlzexternal/driver.c index 26da9c5deb..9c8ed0080f 100644 --- a/bin/tests/system/dlzexternal/driver.c +++ b/bin/tests/system/dlzexternal/driver.c @@ -238,10 +238,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, struct dlz_example_data *state; const char *helper_name; va_list ap; - char soa_data[1024]; - const char *extra; + char soa_data[sizeof("@ hostmaster.root 123 900 600 86400 3600")]; isc_result_t result; - int n; + size_t n; UNUSED(dlzname); @@ -275,19 +274,19 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, sprintf(state->zone_name, "%s.", argv[1]); } + /* + * Use relative names to trigger ISC_R_NOSPACE in dns_sdlz_putrr. + */ if (strcmp(state->zone_name, ".") == 0) { - extra = ".root"; + n = strlcpy(soa_data, + "@ hostmaster.root 123 900 600 86400 3600", + sizeof(soa_data)); } else { - extra = "."; + n = strlcpy(soa_data, "@ hostmaster 123 900 600 86400 3600", + sizeof(soa_data)); } - n = sprintf(soa_data, "%s hostmaster%s%s 123 900 600 86400 3600", - state->zone_name, extra, state->zone_name); - - if (n < 0) { - CHECK(ISC_R_FAILURE); - } - if ((unsigned)n >= sizeof(soa_data)) { + if (n >= sizeof(soa_data)) { CHECK(ISC_R_NOSPACE); } diff --git a/bin/tests/system/dlzexternal/ns1/dlzs.conf.in b/bin/tests/system/dlzexternal/ns1/dlzs.conf.in index 07bf329b50..c679498118 100644 --- a/bin/tests/system/dlzexternal/ns1/dlzs.conf.in +++ b/bin/tests/system/dlzexternal/ns1/dlzs.conf.in @@ -21,6 +21,11 @@ dlz "example three" { database "dlopen ../driver.@SO@ example.org"; }; +dlz "example four" { + // Long zone name to trigger ISC_R_NOSPACE in dns_sdlz_putrr. + database "dlopen ../driver.@SO@ 123456789.123456789.123456789.123456789.123456789.example.foo"; +}; + dlz "unsearched1" { database "dlopen ../driver.@SO@ other.nil"; search no; From 1e908ca07694bb69408205f9efab02df1991b3dc Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 24 Nov 2021 11:20:17 +1100 Subject: [PATCH 3/3] Add CHANGES for [GL #3021] (cherry picked from commit ed5d28088aefd55dcde6eff7c495761dc68bf2f6) --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index cd641a222e..27c9658a65 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5764. [bug] dns_sdlz_putrr failed to process some valid resource + records. [GL #3021] + 5758. [bug] mdig now honors the operating system's preferred ephemeral port range. [GL #2374]