php 8.5: fix deprecated 'double' -> 'float'#547
Conversation
WalkthroughChanged RNG seeding precision in JAXL utility: generateNonce now uses a float cast for microtime when seeding my_mt_srand; nonce generation loop unchanged. No public API or signature changes. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (2)
154-160: Use a CSPRNG for nonce generation (random_bytes / Randomizer->getBytes).Nonce material should be unpredictable. The current approach is based on MT (non-cryptographic). Prefer random_bytes (available since PHP 7.0), and fall back to the existing logic only if unavailable.
Apply this diff:
- public static function generateNonce() { - $str = ''; - my_mt_srand((float) microtime()*10000000); - for($i=0; $i<32; $i++) - $str .= chr(my_mt_rand(0, 255)); - return $str; - } + public static function generateNonce() { + // Prefer cryptographically secure RNG when available + if (function_exists('random_bytes')) { + return random_bytes(32); + } + $str = ''; + my_mt_srand((int) (microtime(true) * 10000000)); + for ($i = 0; $i < 32; $i++) { + $str .= chr(my_mt_rand(0, 255)); + } + return $str; + }
188-200: pbkdf2 is broken: undefined variables ($s, $p, $c) and wrong return var ($dk_len).This function cannot work as written and will produce errors. Fix variable names and logic to match the signature.
- public static function pbkdf2($data, $secret, $iteration, $dkLen=32, $algo='sha1') { - $hLen = strlen(hash($algo, null, true)); - - $l = ceil($dkLen/$hLen); - $t = null; - for($i=1; $i<=$l; $i++) { - $f = $u = hash_hmac($algo, $s.pack('N', $i), $p, true); - for($j=1; $j<$c; $j++) - $f ^= ($u = hash_hmac($algo, $u, $p, true)); - $t .= $f; - } - return substr($t, 0, $dk_len); - } + public static function pbkdf2($salt, $password, $iterations, $dkLen = 32, $algo = 'sha1') { + $hLen = strlen(hash($algo, '', true)); + $l = (int) ceil($dkLen / $hLen); + $t = ''; + for ($i = 1; $i <= $l; $i++) { + $f = $u = hash_hmac($algo, $salt . pack('N', $i), $password, true); + for ($j = 1; $j < $iterations; $j++) { + $u = hash_hmac($algo, $u, $password, true); + $f ^= $u; + } + $t .= $f; + } + return substr($t, 0, $dkLen); + }
🧹 Nitpick comments (2)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (2)
154-160: Seed RNG with an integer and use microtime(true) to avoid string-to-float casts.Casting the default string return of microtime() to float is unnecessary; microtime(true) returns a float directly. Also, seeding with an int avoids implicit float-to-int conversion in both mt_srand and Random\Engine\Mt19937.
Apply this minimal diff:
- my_mt_srand((float) microtime()*10000000); + my_mt_srand((int) (microtime(true) * 10000000));
53-67: Guard against partially specified bounds in my_mt_rand.If only one of $min/$max is provided, getInt will receive null for the other bound (TypeError). mt_rand also requires both bounds or neither. Add validation to enforce "both or none".
function my_mt_rand($min = null, $max = null) { if (version_compare(PHP_VERSION, '8.2.0') >= 0) { if (!isset($GLOBALS['my_mt_rand'])) { $GLOBALS['my_mt_rand'] = new \Random\Randomizer(new \Random\Engine\Mt19937()); } - if ($min === null && $max === null) { - return $GLOBALS['my_mt_rand']->nextInt(); - } - - return $GLOBALS['my_mt_rand']->getInt($min, $max); + if ($min === null && $max === null) { + return $GLOBALS['my_mt_rand']->nextInt(); + } + if ($min !== null && $max !== null) { + return $GLOBALS['my_mt_rand']->getInt($min, $max); + } + throw new \InvalidArgumentException('Both $min and $max must be provided, or neither.'); } else { return mt_rand($min, $max); } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php(1 hunks)
🔇 Additional comments (1)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (1)
156-156: LGTM: replace deprecated (double) cast with (float).This aligns with PHP 8.x deprecations and preserves existing behavior.
|
Added to #549 |
Summary by CodeRabbit
Bug Fixes
Chores