summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeigh <leight@gmail.com>2014-09-24 07:56:46 +0100
committerLeigh <leight@gmail.com>2014-09-24 07:56:46 +0100
commit3e9a31748d50d1b96e8ca82b2399811f8c73a035 (patch)
treeb84782a8d6619df2693b1f0a0176b2a434ebb5f1
parentacd7fcf55f81955e4837c750a5e45f83d3c55ba2 (diff)
downloadphp-git-3e9a31748d50d1b96e8ca82b2399811f8c73a035.tar.gz
Make sure min < max
-rw-r--r--ext/gmp/gmp.c7
-rw-r--r--ext/gmp/tests/gmp_random_range.phpt4
2 files changed, 11 insertions, 0 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 301729d563..2a6cc3d3c0 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -1871,6 +1871,13 @@ ZEND_FUNCTION(gmp_random_range)
FETCH_GMP_ZVAL(gmpnum_min, min_arg, temp_a);
FETCH_GMP_ZVAL(gmpnum_max, max_arg, temp_b);
+ if (mpz_cmp(gmpnum_min, gmpnum_max) > 0) {
+ FREE_GMP_TEMP(temp_a);
+ FREE_GMP_TEMP(temp_b);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The minimum value must be lower than the maximum value");
+ return;
+ }
+
INIT_GMP_RETVAL(gmpnum_result);
gmp_init_random();
diff --git a/ext/gmp/tests/gmp_random_range.phpt b/ext/gmp/tests/gmp_random_range.phpt
index 93074f2913..50afafd4e9 100644
--- a/ext/gmp/tests/gmp_random_range.phpt
+++ b/ext/gmp/tests/gmp_random_range.phpt
@@ -5,7 +5,11 @@ gmp_random_range() basic tests
--FILE--
<?php
+var_dump(gmp_random_range(1, -1));
+
echo "Done\n";
?>
--EXPECTF--
+Warning: gmp_random_range(): The minimum value must be lower than the maximum value in %s on line %d
+NULL
Done