2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 07:35:26 +00:00

Ensure keyname buffer is big enough

Use a temporary string rather than a fixed buffer to construct
the keyname.
This commit is contained in:
Mark Andrews
2024-01-05 17:36:00 +11:00
parent 7cced1732d
commit 95de7f829c

View File

@@ -3236,12 +3236,17 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
"zone '%s': is not a valid name", znamestr); "zone '%s': is not a valid name", znamestr);
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
} else { } else {
char namebuf[DNS_NAME_FORMATSIZE + 128]; char namebuf[DNS_NAME_FORMATSIZE];
char *tmp = namebuf; char classbuf[DNS_RDATACLASS_FORMATSIZE];
size_t len = sizeof(namebuf); char *key = NULL;
const char *vname = NULL;
size_t len = 0;
int n;
zname = dns_fixedname_name(&fixedname); zname = dns_fixedname_name(&fixedname);
dns_name_format(zname, namebuf, sizeof(namebuf)); dns_name_format(zname, namebuf, sizeof(namebuf));
dns_rdataclass_format(zclass, classbuf, sizeof(classbuf));
tresult = exists( tresult = exists(
zconfig, namebuf, zconfig, namebuf,
ztype == CFG_ZONE_HINT ? 1 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)) { } else if (dns_name_isula(zname)) {
ula = true; ula = true;
} }
len -= strlen(tmp); vname = (ztype == CFG_ZONE_INVIEW) ? target
tmp += strlen(tmp); : (viewname != NULL) ? viewname
(void)snprintf(tmp, len, "%u/%s", zclass, : "_default";
(ztype == CFG_ZONE_INVIEW) ? target len = strlen(namebuf) + strlen(classbuf) + strlen(vname) + 3;
: (viewname != NULL) ? viewname key = isc_mem_get(mctx, len);
: "_default"); n = snprintf(key, len, "%s/%s/%s", namebuf, classbuf, vname);
RUNTIME_CHECK(n > 0 && (size_t)n < len);
switch (ztype) { switch (ztype) {
case CFG_ZONE_INVIEW: 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) { if (tresult != ISC_R_SUCCESS) {
cfg_obj_log(inviewobj, logctx, ISC_LOG_ERROR, cfg_obj_log(inviewobj, logctx, ISC_LOG_ERROR,
"'in-view' zone '%s' " "'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_MIRROR:
case CFG_ZONE_HINT: case CFG_ZONE_HINT:
case CFG_ZONE_STUB: case CFG_ZONE_STUB:
case CFG_ZONE_STATICSTUB: case CFG_ZONE_STATICSTUB: {
tmp = isc_mem_strdup(mctx, namebuf); 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; result = tresult;
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;
}
} }
break; } break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
isc_mem_put(mctx, key, len);
} }
if (ztype == CFG_ZONE_INVIEW) { if (ztype == CFG_ZONE_INVIEW) {