Skip to content

Commit

Permalink
replace rand() & mt_rand() by random_int()
Browse files Browse the repository at this point in the history
These functions will be deprecated in PHP 8.3
https://wiki.php.net/rfc/deprecations_php_8_3

Replace them by random_int() which also has a userland implementation for PHP
< 7.0 that we already use in this project (paragonie/random_compat)
  • Loading branch information
tenzap committed Sep 24, 2023
1 parent d37c479 commit 6179781
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions application/models/gateway/Gammu_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function send_messages($data)

// generate UDH
$UDH = '050003';
$hex = dechex(mt_rand(0, 255));
$hex = dechex(random_int(0, 255));
$hex = str_pad($hex, 2, '0', STR_PAD_LEFT);
$UDH .= strtoupper($hex);
$data['UDH'] = $UDH;
Expand Down Expand Up @@ -1455,7 +1455,7 @@ function copy_message($msg_id)
$newUDH = '';
for ($j = 1; $j <= 4; $j++)
{
$newUDH .= strtoupper(dechex(mt_rand(0, 255)));
$newUDH .= strtoupper(dechex(random_int(0, 255)));
}
$data->UDH = $newUDH.substr($data->UDH, -4);
}
Expand Down
2 changes: 1 addition & 1 deletion application/models/gateway/Way2sms_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function sendWay2SMS($uid, $pwd, $phone, $msg)
$uid = urlencode($uid);
$pwd = urlencode($pwd);

$autobalancer = rand(1, 8);
$autobalancer = random_int(1, 8);

curl_setopt($curl, CURLOPT_URL, 'http://site'.$autobalancer.'.way2sms.com/Login1.action');
curl_setopt($curl, CURLOPT_POST, 1);
Expand Down
2 changes: 1 addition & 1 deletion application/plugins/sms_to_twitter/libraries/Epi.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected function generateNonce()
if(isset($this->nonce)) // for unit testing
return $this->nonce;

return md5(uniqid(rand(), true));
return md5(uniqid(random_int(0, PHP_INT_MAX), true));
}

// parameters should already have been passed through prepareParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function out($payload) {
}

public static function loadSession($jaxl) {
$jaxl->bosh['rid'] = isset($_SESSION['jaxl_rid']) ? (string) $_SESSION['jaxl_rid'] : rand(1000, 10000);
$jaxl->bosh['rid'] = isset($_SESSION['jaxl_rid']) ? (string) $_SESSION['jaxl_rid'] : random_int(1000, 10000);
$jaxl->bosh['sid'] = isset($_SESSION['jaxl_sid']) ? (string) $_SESSION['jaxl_sid'] : false;
$jaxl->lastid = isset($_SESSION['jaxl_id']) ? $_SESSION['jaxl_id'] : $jaxl->lastid;
$jaxl->jid = isset($_SESSION['jaxl_jid']) ? $_SESSION['jaxl_jid'] : $jaxl->jid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function __construct($config) {
$this->clocked = $this->startTime = time();

/* Parse configuration parameter */
$this->lastid = rand(1, 9);
$this->lastid = random_int(1, 9);
$this->streamTimeout = isset($config['streamTimeout']) ? $config['streamTimeout'] : 20;
$this->rateLimit = isset($config['rateLimit']) ? $config['rateLimit'] : true;
$this->getPktSize = isset($config['getPktSize']) ? $config['getPktSize'] : 4096;
Expand Down

0 comments on commit 6179781

Please sign in to comment.