DEP8 error on armhf (32bits): long2ip() requires int
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Cacti |
Fix Released
|
Unknown
|
|||
cacti (Ubuntu) |
Fix Released
|
Undecided
|
Andreas Hasenack |
Bug Description
Starting with php 7.1 (or so I'm told), long2ip() requires an integer. Turns out that on 32bit a number bigger than MAXINT is a "float" (?):
$ cat long2ip.php
<?php
echo "PHP_INT_MAX = " . PHP_INT_MAX . "\n";
echo "long2ip(
echo "long2ip(
echo "long2ip(-1) = " . long2ip(-1) . "\n";
?>
$ php ./long2ip.php
PHP_INT_MAX = 2147483647
long2ip(
PHP Warning: long2ip() expects parameter 1 to be int, float given in /home/ubuntu/
long2ip(PHP_INT_MAX + 1) =
long2ip(-1) = 255.255.255.255
$ uname -a
Linux f1-armhf 5.4.0-14-generic #17-Ubuntu SMP Thu Feb 6 22:49:16 UTC 2020 armv8l armv8l armv8l GNU/Linux
This seems to be happening in the cacti dep8 tests:
02/27/2020 12:55:07 - ERROR PHP WARNING: long2ip() expects parameter 1 to be int, float given in file: /usr/share/
02/27/2020 12:55:07 - CMDPHP PHP ERROR WARNING Backtrace: (/poller_
02/27/2020 12:55:07 - ERROR PHP WARNING: long2ip() expects parameter 1 to be int, float given in file: /usr/share/
02/27/2020 12:55:07 - CMDPHP PHP ERROR WARNING Backtrace: (/poller_
I'm not sure what value long2ip() is getting. I'm assuming it's a random network, and sometimes (most of the time?) it's larger than MAXINT. Or some other garbage, and long2ip() barfs.
This test hasn't always failed, hence my assumption above. I'll try to add some debugging to see what is being passed to that function.
Related branches
- Christian Ehrhardt (community): Approve
- Canonical Server: Pending requested
-
Diff: 55 lines (+33/-0)3 files modifieddebian/changelog (+7/-0)
debian/patches/fix-32bit-ip-conversion.patch (+25/-0)
debian/patches/series (+1/-0)
Changed in cacti (Ubuntu): | |
assignee: | nobody → Andreas Hasenack (ahasenack) |
status: | New → In Progress |
Changed in cacti: | |
status: | Unknown → Fix Released |
I believe the bug is in lib/api_ automation. php's automation_ get_valid_ mask($range) function.
It uses bindec() to convert binary to integer, but the result of bindec() is unsigned integer, or float if it's too big for an integer[1]. On 32bit turns out it's too big for an integer, a float is returned, and things break.
On 64bit:
php ./test.php 24
bindec( 111111111111111 111111111000000 00):
4294967040
Array
(
[cidr] => 24
[subnet] => 255.255.255.0
[count] => 255
)
Same code on 32bits:
ubuntu@f1-armhf:~$ php ./test.php 24
bindec( 111111111111111 111111111000000 00): test.php on line 13
4294967040PHP Warning: long2ip() expects parameter 1 to be int, float given in /home/ubuntu/
Array
(
[cidr] => 24
[subnet] =>
[count] => 255
)
1. https:/ /www.php. net/manual/ en/function. bindec. php