leenooks / phpLDAPadmin

phpLDAPadmin - Web based LDAP administration tool
www.phpldapadmin.org
GNU General Public License v2.0
523 stars 166 forks source link

PHP Deprecated: Implicit conversion from float 0.75 to int loses precision in createlm.php #193

Closed vpushkar closed 1 year ago

vpushkar commented 1 year ago

Inside smb_hash function the division operator ("/") returns a float value used as array index which throws "Implicit conversion from float to int loses precision" exception with php 8.1. This can be fixed as following:

--- createlm.php.bak    2023-03-05 06:49:59.683836000 +0200
+++ createlm.php        2023-03-05 10:13:35.645811000 +0200
@@ -284,8 +284,8 @@
                $key2 = $this->str_to_key($key);

                for ($i = 0; $i < 64; $i++) {
-                       $inb[$i] = ($in[$i/8] & (1<<(7-($i%8)))) ? 1:0;
-                       $keyb[$i] = ($key2[$i/8] & (1<<(7-($i%8)))) ? 1:0;
+                       $inb[$i] = ($in[intdiv($i, 8)] & (1<<(7-($i%8)))) ? 1:0;
+                       $keyb[$i] = ($key2[intdiv($i, 8)] & (1<<(7-($i%8)))) ? 1:0;
                        $outb[$i] = 0;
                }
                $outb = $this->doHash($inb, $keyb, $forw);
@@ -294,7 +294,7 @@
                }
                for ($i = 0; $i < 64; $i++) {
                        if ( $outb[$i] )  {
-                               $out[$i/8] |= (1<<(7-($i%8)));
+                               $out[intdiv($i, 8)] |= (1<<(7-($i%8)));
                        }
                }
                return $out;