fix: validate random_int parameters in Helper::randomPort to prevent min > max error

This commit is contained in:
xboard
2026-03-09 06:32:10 +08:00
parent 96cb398315
commit fad6441f4c

View File

@@ -142,8 +142,13 @@ class Helper
}
public static function randomPort($range): int {
$portRange = explode('-', $range);
return random_int((int)$portRange[0], (int)$portRange[1]);
$portRange = explode('-', (string) $range, 2);
$min = (int) ($portRange[0] ?? 0);
$max = (int) ($portRange[1] ?? $portRange[0] ?? 0);
if ($min > $max) {
[$min, $max] = [$max, $min];
}
return random_int($min, $max);
}
public static function base64EncodeUrlSafe($data)