From f0a879491d9c356830d920b54e5144c41baa4449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:30:38 -0300 Subject: [PATCH] fix(dhcp): avoid infinite loop building IPv6 reverse zones getzonesfornet() derives the number of reverse-zone nibbles as $nibbs = $maskbits / 4, then decrements it once per hex nibble of the network prefix. For a sub-nibble (not 4-bit-aligned) IPv6 mask $nibbs can go negative before the padding loop, and `while ($nibbs)` then never terminates: it keeps decrementing past zero while appending "0." to $rev, spinning forever and growing the string until the process is killed. Make the padding loop `while ($nibbs > 0)` so it can never run away, and return early only when $nibbs is genuinely negative. $nibbs == 0 is the normal nibble-aligned case (e.g. a /64) and must still emit its reverse zone. Recovered from the unmerged lenovobuild branch (original 0e070cd2). The original guarded with `$nibbs < 1`, which also dropped the valid $nibbs == 0 case and left standard /64 subnets with no reverse zone; corrected to `$nibbs < 0` after lab validation on a real provisioning cluster. Co-authored-by: Jarrod Johnson <10814490+jjohnson42@users.noreply.github.com> --- xCAT-server/lib/xcat/plugins/dhcp.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 4483c46ca..49b232089 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -3629,7 +3629,13 @@ sub getzonesfornet { $rev .= $_ . "."; $nibbs--; } - while ($nibbs) { + if ($nibbs < 0) { + # a sub-nibble (not 4-bit-aligned) IPv6 mask leaves $nibbs negative; + # bail rather than spin forever in the loop below. $nibbs == 0 is the + # normal nibble-aligned case (e.g. a /64) and must still emit a zone. + return (); + } + while ($nibbs > 0) { $rev .= "0."; $nibbs--; }