Skip to content

Commit fad6441

Browse files
author
xboard
committed
fix: validate random_int parameters in Helper::randomPort to prevent min > max error
1 parent 96cb398 commit fad6441

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/Utils/Helper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ public static function getSubscribeUrl(string $token, $subscribeUrl = null)
142142
}
143143

144144
public static function randomPort($range): int {
145-
$portRange = explode('-', $range);
146-
return random_int((int)$portRange[0], (int)$portRange[1]);
145+
$portRange = explode('-', (string) $range, 2);
146+
$min = (int) ($portRange[0] ?? 0);
147+
$max = (int) ($portRange[1] ?? $portRange[0] ?? 0);
148+
if ($min > $max) {
149+
[$min, $max] = [$max, $min];
150+
}
151+
return random_int($min, $max);
147152
}
148153

149154
public static function base64EncodeUrlSafe($data)

0 commit comments

Comments
 (0)