From 5ab4dc298327d3a8d51387959d6905c6bb24fd99 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 5 Mar 2011 22:16:50 +0100 Subject: [ticket/10042] Add mt_rand() wrapper which allows swapping $min and $max. PHPBB3-10042 --- phpBB/includes/functions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 398a02380b..259b3b0481 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -244,6 +244,22 @@ function unique_id($extra = 'c') return substr($val, 4, 16); } +/** +* Wrapper for mt_rand() which allows swapping $min and $max parameters. +* +* PHP does not allow us to swap the order of the arguments for mt_rand() anymore. +* (since PHP 5.3.4, see http://bugs.php.net/46587) +* +* @param int $min Lowest value to be returned +* @param int $max Highest value to be returned +* +* @return int Random integer between $min and $max (or $max and $min) +*/ +function phpbb_mt_rand($min, $max) +{ + return ($min > $max) ? mt_rand($max, $min) : mt_rand($min, $max); +} + /** * Return formatted string for filesizes * -- cgit v1.2.1 From c6c2a23ecb10b4b54e7e9b703d14e8c7cda6ad55 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 5 Mar 2011 22:20:23 +0100 Subject: [ticket/10042] GD CAPTCHA: Round offset to the next pixel. PHPBB3-10042 --- phpBB/includes/captcha/captcha_gd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/includes/captcha/captcha_gd.php index 96e39af85b..7a3f4f46ab 100644 --- a/phpBB/includes/captcha/captcha_gd.php +++ b/phpBB/includes/captcha/captcha_gd.php @@ -77,7 +77,7 @@ class captcha { $denom = ($code_len - $i); $denom = max(1.3, $denom); - $offset[$i] = mt_rand(0, (1.5 * $width_avail) / $denom); + $offset[$i] = mt_rand(0, (int) round((1.5 * $width_avail) / $denom)); $width_avail -= $offset[$i]; } -- cgit v1.2.1 From 18daf6345f64e59f651c43a3150d9e139ac2a4cc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 5 Mar 2011 22:21:45 +0100 Subject: [ticket/10042] GD CAPTCHA: Call phpbb_mt_rand() where required. PHPBB3-10042 --- phpBB/includes/captcha/captcha_gd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/includes/captcha/captcha_gd.php index 7a3f4f46ab..6d859a4ecc 100644 --- a/phpBB/includes/captcha/captcha_gd.php +++ b/phpBB/includes/captcha/captcha_gd.php @@ -77,7 +77,7 @@ class captcha { $denom = ($code_len - $i); $denom = max(1.3, $denom); - $offset[$i] = mt_rand(0, (int) round((1.5 * $width_avail) / $denom)); + $offset[$i] = phpbb_mt_rand(0, (int) round((1.5 * $width_avail) / $denom)); $width_avail -= $offset[$i]; } -- cgit v1.2.1