From: Colin Vidal Date: Mon, 17 Nov 2025 11:33:48 +0000 (+0100) Subject: enforces bounds of prefetch statement X-Git-Tag: v9.21.16~48^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c038c2fa2c74a07c08d50e621b48fcff9125ad1;p=thirdparty%2Fbind9.git enforces bounds of prefetch statement The prefetch statement now enforces its bounds. The configuration (including `named-checkconf`) now fails if the trigger (first value) is above 10, or if the eligibility (second optional value) isn't at least six seconds more than the trigger value. --- diff --git a/bin/tests/system/checkconf/bad-prefetch1.conf b/bin/tests/system/checkconf/bad-prefetch1.conf new file mode 100644 index 00000000000..8051c63167a --- /dev/null +++ b/bin/tests/system/checkconf/bad-prefetch1.conf @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + prefetch 11; +}; diff --git a/bin/tests/system/checkconf/bad-prefetch2.conf b/bin/tests/system/checkconf/bad-prefetch2.conf new file mode 100644 index 00000000000..a2419a1d1aa --- /dev/null +++ b/bin/tests/system/checkconf/bad-prefetch2.conf @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + prefetch 2 7; +}; diff --git a/bin/tests/system/checkconf/bad-prefetch3.conf b/bin/tests/system/checkconf/bad-prefetch3.conf new file mode 100644 index 00000000000..adee152be78 --- /dev/null +++ b/bin/tests/system/checkconf/bad-prefetch3.conf @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +view foo { + prefetch 11; +}; diff --git a/bin/tests/system/checkconf/bad-prefetch4.conf b/bin/tests/system/checkconf/bad-prefetch4.conf new file mode 100644 index 00000000000..5fc48c077e4 --- /dev/null +++ b/bin/tests/system/checkconf/bad-prefetch4.conf @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +view foo { + prefetch 9 13; +}; diff --git a/lib/isccfg/check.c b/lib/isccfg/check.c index fb1e1d92b91..f8c16974579 100644 --- a/lib/isccfg/check.c +++ b/lib/isccfg/check.c @@ -1999,6 +1999,37 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config, } } + obj = NULL; + (void)cfg_map_get(options, "prefetch", &obj); + if (obj != NULL) { + const cfg_obj_t *trigger = cfg_tuple_get(obj, "trigger"); + const cfg_obj_t *eligible = cfg_tuple_get(obj, "eligible"); + uint32_t tvalue = cfg_obj_asuint32(trigger); + + if (tvalue > 10) { + cfg_obj_log(obj, ISC_LOG_ERROR, + "prefetch '%u' out of range (0..10)", + tvalue); + if (result == ISC_R_SUCCESS) { + result = ISC_R_RANGE; + } + } + + if (!cfg_obj_isvoid(eligible)) { + uint32_t evalue = cfg_obj_asuint32(eligible); + if (evalue < tvalue + 6) { + cfg_obj_log(obj, ISC_LOG_ERROR, + "prefetch eligibility '%u' must be " + "at least six seconds longer than " + "the trigger value '%u'", + evalue, tvalue); + if (result == ISC_R_SUCCESS) { + result = ISC_R_RANGE; + } + } + } + } + if (aclctx != NULL) { cfg_aclconfctx_detach(&aclctx); } diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 0145f2b4848..e2d5796ed9d 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -2237,9 +2237,6 @@ prefetch_merge(cfg_obj_t *effectiveobj, const cfg_obj_t *defaultobj) { trigger = (cfg_obj_t *)cfg_tuple_get(effectiveobj, "trigger"); INSIST(cfg_obj_isuint32(trigger)); - if (cfg_obj_asuint32(trigger) > 10) { - trigger->value.uint32 = 10; - } eligible = (cfg_obj_t *)cfg_tuple_get(effectiveobj, "eligible"); if (cfg_obj_isvoid(eligible)) { @@ -2253,9 +2250,6 @@ prefetch_merge(cfg_obj_t *effectiveobj, const cfg_obj_t *defaultobj) { } INSIST(cfg_obj_isuint32(eligible)); - if (cfg_obj_asuint32(eligible) < cfg_obj_asuint32(trigger) + 6) { - eligible->value.uint32 = cfg_obj_asuint32(trigger) + 6; - } } static void