Commit 2cb4897346 for bind

commit 2cb4897346d35e85bbe70a92ffdd661b97544db1
Author: Colin Vidal <colin@isc.org>
Date:   Wed Nov 25 11:04:44 2026 +0100

    Ensures `named -n` is less than `ISC_TID_MAX`

    Early and gracefully shutdown of `named` if `-n` option is used with a
    number equals or more than `ISC_TID_MAX`. (Currently, 512.)

diff --git a/bin/named/main.c b/bin/named/main.c
index 6a6a9bea88..c582fd3d7a 100644
--- a/bin/named/main.c
+++ b/bin/named/main.c
@@ -903,6 +903,12 @@ parse_command_line(int argc, char *argv[]) {
 			if (named_g_cpus == 0) {
 				named_g_cpus = 1;
 			}
+
+			if (named_g_cpus >= ISC_TID_MAX) {
+				named_main_earlyfatal(
+					"number of cpus must be less than %d",
+					ISC_TID_MAX);
+			}
 			break;
 		case 'p':
 			parse_port(isc_commandline_argument);
diff --git a/bin/tests/system/cpu/ns1/named.args.j2 b/bin/tests/system/cpu/ns1/named.args.j2
new file mode 100644
index 0000000000..bacb6cacea
--- /dev/null
+++ b/bin/tests/system/cpu/ns1/named.args.j2
@@ -0,0 +1,3 @@
+{% set cpus = cpus | default("") %}
+
+-m record -c named.conf -d 99 -D cpu-ns1 -g @cpus@
diff --git a/bin/tests/system/cpu/tests_number_of_cpus.py b/bin/tests/system/cpu/tests_number_of_cpus.py
new file mode 100644
index 0000000000..c24cb00640
--- /dev/null
+++ b/bin/tests/system/cpu/tests_number_of_cpus.py
@@ -0,0 +1,30 @@
+# 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.
+
+import os
+import subprocess
+
+
+def test_number_of_cpus(ns1, templates):
+    ns1.stop()
+
+    templates.render(
+        f"{ns1.identifier}/named.args",
+        {"cpus": "-n 512"},
+    )
+
+    failed = False
+    try:
+        ns1.start(["--noclean", "--restart", "--port", os.environ["PORT"]])
+    except subprocess.CalledProcessError:
+        failed = True
+    assert failed
+    assert len(ns1.log.grep("number of cpus must be less than 512")) == 1
diff --git a/bin/tests/system/cpu/tests_sh_cpu.py b/bin/tests/system/cpu/tests_sh_cpu.py
index 2916aeaf97..53d5f78a2a 100644
--- a/bin/tests/system/cpu/tests_sh_cpu.py
+++ b/bin/tests/system/cpu/tests_sh_cpu.py
@@ -17,6 +17,7 @@ EXTRA_ARTIFACTS = pytest.mark.extra_artifacts(
     [
         "named.run.*",
         "ns1/managed-keys.*",
+        "ns1/named.args",
     ]
 )