mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-21 16:39:30 +00:00
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 (original0e070cd2). 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> (cherry picked from commitf0a879491d)
This commit is contained in:
committed by
github-actions[bot]
parent
3023a4b14d
commit
02557a42b3
@@ -3620,7 +3620,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--;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user