Skip to content

Commit ed1f1c8

Browse files
committed
Fix boundary checks for Randomizer::getFloat()
For the non-closed intervals both boundaries must be distinct.
1 parent 331009c commit ed1f1c8

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

ext/random/randomizer.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,26 +240,41 @@ PHP_METHOD(Random_Randomizer, getFloat)
240240
RETURN_THROWS();
241241
#endif
242242

243-
if (UNEXPECTED(max < min)) {
244-
zend_argument_value_error(2, "must be greater than or equal to argument #1 ($min)");
245-
RETURN_THROWS();
246-
}
247-
248243
if (bounds) {
249244
zval *case_name = zend_enum_fetch_case_name(bounds);
250245
bounds_name = Z_STR_P(case_name);
251246
}
252247

253248
if (zend_string_equals_literal(bounds_name, "ClosedOpen")) {
249+
if (UNEXPECTED(max <= min)) {
250+
zend_argument_value_error(2, "must be greater than argument #1 ($min)");
251+
RETURN_THROWS();
252+
}
253+
254254
RETURN_DOUBLE(getFloat_closed_open(randomizer->algo, randomizer->status, min, max));
255255
}
256256
if (zend_string_equals_literal(bounds_name, "ClosedClosed")) {
257+
if (UNEXPECTED(max < min)) {
258+
zend_argument_value_error(2, "must be greater than or equal to argument #1 ($min)");
259+
RETURN_THROWS();
260+
}
261+
257262
RETURN_DOUBLE(getFloat_closed_closed(randomizer->algo, randomizer->status, min, max));
258263
}
259264
if (zend_string_equals_literal(bounds_name, "OpenClosed")) {
265+
if (UNEXPECTED(max <= min)) {
266+
zend_argument_value_error(2, "must be greater than argument #1 ($min)");
267+
RETURN_THROWS();
268+
}
269+
260270
RETURN_DOUBLE(getFloat_open_closed(randomizer->algo, randomizer->status, min, max));
261271
}
262272
if (zend_string_equals_literal(bounds_name, "OpenOpen")) {
273+
if (UNEXPECTED(max <= min)) {
274+
zend_argument_value_error(2, "must be greater than argument #1 ($min)");
275+
RETURN_THROWS();
276+
}
277+
263278
RETURN_DOUBLE(getFloat_open_open(randomizer->algo, randomizer->status, min, max));
264279
}
265280
ZEND_UNREACHABLE();

0 commit comments

Comments
 (0)