com php-src: Make sure min < max: ext/gmp/gmp.c ext/gmp/tests/g mp_random_range.phpt
| From: | Stanislav Malyshev | Date: | Wed, 24 Sep 2014 06:56:46 +0000 |
| Subject: | com php-src: Make sure min < max: ext/gmp/gmp.c ext/gmp/tests/g mp_random_range.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82279@lists.php.net to get a copy of this message | ||
Commit: 3e9a31748d50d1b96e8ca82b2399811f8c73a035
Author: Leigh <leight@gmail.com> Wed, 24 Sep 2014 07:56:46 +0100
Parents: acd7fcf55f81955e4837c750a5e45f83d3c55ba2
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3e9a31748d50d1b96e8ca82b2399811f8c73a035
Log:
Make sure min < max
Changed paths:
M ext/gmp/gmp.c
M ext/gmp/tests/gmp_random_range.phpt
Diff:
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 301729d..2a6cc3d 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 93074f2..50afafd 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