php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69803 gmp_random_range() modifies second parameter if GMP number
Submitted: 2015-06-11 19:38 UTC Modified: 2015-06-11 19:47 UTC
From: andy dot shawaluk at pkware dot com Assigned: nikic (profile)
Status: Closed Package: GNU MP related
PHP Version: master-Git-2015-06-11 (snap) OS: Windows 7
Private report: No CVE-ID: None
 [2015-06-11 19:38 UTC] andy dot shawaluk at pkware dot com
Description:
------------
When calling the gmp_random_range($min,$max) function where $max is a GMP number, the value of $max is modified - after the function returns, it is reduced by ($min-1).

If $max is an ordinary integer (as shown in the online help page), this does not happen.

Tested with latest Windows Master snapshot (VC11 x86 Thread Safe), retrieved from http://windows.php.net/snapshots/ on 2015/06/11 14:34 CDT.

Revision: r7ec3016 (June 09 2015, 17:20:07)

Test script:
---------------
<?php
$a = gmp_init('100'); $b = gmp_init('200');
echo gmp_strval($a) .", ". gmp_strval($b) ."\n";
$c = gmp_random_range($a, $b);
echo gmp_strval($a) .", ". gmp_strval($b) ." -> ". gmp_strval($c) ."\n";

Expected result:
----------------
100, 200
100, 200 -> [number between 100 and 200 inclusive]

Actual result:
--------------
100, 200
100, 101 -> [number between 100 and 200 inclusive]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-11 19:47 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2015-06-11 19:47 UTC] nikic@php.net
Also applies to 5.6: http://3v4l.org/ndepv
 [2015-06-11 20:21 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1acf55eb752db482509d2f9c48443466f9a1bf68
Log: Fixed bug #69803
 [2015-06-11 20:21 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1acf55eb752db482509d2f9c48443466f9a1bf68
Log: Fixed bug #69803
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC