From 95de7f829cde5f3cbb66ce65a2af8f48ee2a9259 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 5 Jan 2024 17:36:00 +1100 Subject: [PATCH] Ensure keyname buffer is big enough Use a temporary string rather than a fixed buffer to construct the keyname. --- lib/isccfg/check.c | 49 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/isccfg/check.c b/lib/isccfg/check.c index 2dcead8ec7..05fcddee6c 100644 --- a/lib/isccfg/check.c +++ b/lib/isccfg/check.c @@ -3236,12 +3236,17 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, "zone '%s': is not a valid name", znamestr); result = ISC_R_FAILURE; } else { - char namebuf[DNS_NAME_FORMATSIZE + 128]; - char *tmp = namebuf; - size_t len = sizeof(namebuf); + char namebuf[DNS_NAME_FORMATSIZE]; + char classbuf[DNS_RDATACLASS_FORMATSIZE]; + char *key = NULL; + const char *vname = NULL; + size_t len = 0; + int n; zname = dns_fixedname_name(&fixedname); dns_name_format(zname, namebuf, sizeof(namebuf)); + dns_rdataclass_format(zclass, classbuf, sizeof(classbuf)); + tresult = exists( zconfig, namebuf, ztype == CFG_ZONE_HINT ? 1 @@ -3260,15 +3265,16 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, } else if (dns_name_isula(zname)) { ula = true; } - len -= strlen(tmp); - tmp += strlen(tmp); - (void)snprintf(tmp, len, "%u/%s", zclass, - (ztype == CFG_ZONE_INVIEW) ? target - : (viewname != NULL) ? viewname - : "_default"); + vname = (ztype == CFG_ZONE_INVIEW) ? target + : (viewname != NULL) ? viewname + : "_default"; + len = strlen(namebuf) + strlen(classbuf) + strlen(vname) + 3; + key = isc_mem_get(mctx, len); + n = snprintf(key, len, "%s/%s/%s", namebuf, classbuf, vname); + RUNTIME_CHECK(n > 0 && (size_t)n < len); switch (ztype) { case CFG_ZONE_INVIEW: - tresult = isc_symtab_lookup(inview, namebuf, 0, NULL); + tresult = isc_symtab_lookup(inview, key, 0, NULL); if (tresult != ISC_R_SUCCESS) { cfg_obj_log(inviewobj, logctx, ISC_LOG_ERROR, "'in-view' zone '%s' " @@ -3291,25 +3297,22 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, case CFG_ZONE_MIRROR: case CFG_ZONE_HINT: case CFG_ZONE_STUB: - case CFG_ZONE_STATICSTUB: - tmp = isc_mem_strdup(mctx, namebuf); + case CFG_ZONE_STATICSTUB: { + char *tmp = isc_mem_strdup(mctx, key); + isc_symvalue_t symvalue; + symvalue.as_cpointer = NULL; + tresult = isc_symtab_define(inview, tmp, 1, symvalue, + isc_symexists_replace); + if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) { - isc_symvalue_t symvalue; - symvalue.as_cpointer = NULL; - tresult = isc_symtab_define( - inview, tmp, 1, symvalue, - isc_symexists_replace); - if (result == ISC_R_SUCCESS && - tresult != ISC_R_SUCCESS) - { - result = tresult; - } + result = tresult; } - break; + } break; default: UNREACHABLE(); } + isc_mem_put(mctx, key, len); } if (ztype == CFG_ZONE_INVIEW) {