]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
enforces bounds of prefetch statement
authorColin Vidal <colin@isc.org>
Mon, 17 Nov 2025 11:33:48 +0000 (12:33 +0100)
committerColin Vidal <colin@isc.org>
Tue, 18 Nov 2025 09:19:15 +0000 (10:19 +0100)
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.

bin/tests/system/checkconf/bad-prefetch1.conf [new file with mode: 0644]
bin/tests/system/checkconf/bad-prefetch2.conf [new file with mode: 0644]
bin/tests/system/checkconf/bad-prefetch3.conf [new file with mode: 0644]
bin/tests/system/checkconf/bad-prefetch4.conf [new file with mode: 0644]
lib/isccfg/check.c
lib/isccfg/namedconf.c

diff --git a/bin/tests/system/checkconf/bad-prefetch1.conf b/bin/tests/system/checkconf/bad-prefetch1.conf
new file mode 100644 (file)
index 0000000..8051c63
--- /dev/null
@@ -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 (file)
index 0000000..a2419a1
--- /dev/null
@@ -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 (file)
index 0000000..adee152
--- /dev/null
@@ -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 (file)
index 0000000..5fc48c0
--- /dev/null
@@ -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;
+};
index fb1e1d92b91546106e460917ede3943dd77714f9..f8c169745790d5663a3c4d5b8c855282dc22c806 100644 (file)
@@ -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);
        }
index 0145f2b484878d5652c9d08eb0626331fcf16bac..e2d5796ed9dd6c286713dcba44c7ef2e3cce8af5 100644 (file)
@@ -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