-
-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using 32-bit OS, automation errors can be seen due to subnet mask calculations #3310
Comments
Can you do a pull request against the 1.2.x branch? |
I wonder if this is enough to fix it? I'm wary of casting variable types and its behavior between different architectures: diff --git a/lib/api_automation.php b/lib/api_automation.php
index a1373af08..c71b08705 100644
--- a/lib/api_automation.php
+++ b/lib/api_automation.php
@@ -3003,7 +3003,7 @@ function automation_get_valid_mask($range) {
$cidr = $range;
$mask = array(
'cidr' => $cidr,
- 'subnet' => long2ip(bindec(str_repeat('1',$range) . str_repeat('0',32-$range))));
+ 'subnet' => long2ip((int)bindec(str_repeat('1',$range) . str_repeat('0',32-$range))));
} else {
$mask = false;
} |
With the casting change you mean? |
Maybe this is better: diff --git a/lib/api_automation.php b/lib/api_automation.php
index a1373af08..b9fffbeeb 100644
--- a/lib/api_automation.php
+++ b/lib/api_automation.php
@@ -3003,7 +3003,7 @@ function automation_get_valid_mask($range) {
$cidr = $range;
$mask = array(
'cidr' => $cidr,
- 'subnet' => long2ip(bindec(str_repeat('1',$range) . str_repeat('0',32-$range))));
+ 'subnet' => long2ip((2**$range-1) << (32-$range)))
} else {
$mask = false;
} |
Has this been tested against PHP 5.4 or 5.5? I suspect not as I just noticed that Travis has moaned about the use of 2** |
No, I didn't test against those versions of php. Is there no ** operator there, or is it an issue with parenthesis? |
I was not sure, I briefly saw that Travis didn't like it, so I looked at the php docs:
So, we can only use that if PHP 5.4 or later, which unfortunately mean we either roll back the change or make an if statement and accept that under 5.4/5.5, there is a flaw in the logic on little endian systems making it a known issue. |
I'll see if I can come up with something tomorrow
…On Thu, Mar 5, 2020, 20:39 Mark Brugnoli-Vinten ***@***.***> wrote:
I was not sure, I briefly saw that Travis didn't like it, so I looked at
the php docs:
$a ** $b | Exponentiation | Result of raising $a to the $b'th power.
Introduced in PHP 5.6.
So, we can only use that if PHP 5.4 or later, which unfortunately mean we
either roll back the change or make an if statement and accept that under
5.4/5.5, there is a flaw in the logic on little endian systems making it a
known issue.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3310?email_source=notifications&email_token=ABHBKGWOQMSKHBPTOKK77L3RGAZ33A5CNFSM4K7YCCEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEN7HGBQ#issuecomment-595489542>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHBKGTSI4YHK2MWQNF26ULRGAZ33ANCNFSM4K7YCCEA>
.
|
That would be good thanks as unfortunately I don't have a system to test that against. Took me a while to come up with my original code but yours was a lot simpler :) Could we reverse the bit order depending on the endian using my original code for older PHP versions? |
How far back in terms of PHP do you need to go? |
If you prefer to leave your old code with "1" and "0" strings, then maybe the I did test the The oldest php I can get is the one from Ubuntu Precise: 5.3.10. |
This worked on precise's php 5.3.10: 'subnet' => long2ip((pow(2,$range)-1) << (32-$range))); Let me try on other architectures now. |
The oldest php I can get on big-endian (s390x in this case) is php 7.0.33, from ubuntu xenial, same from debian stretch. The script keeps working fine there, with the |
Sure if you already have it that would be great :) Otherwise I can just apply the change over the weekend. |
The |
Yes, I believe so. Be nice when PHP 5 is no longer a worry. |
Describe the bug
Function
automation_get_valid_mask()
fails in in https://github.com/Cacti/cacti/blob/develop/lib/api_automation.php#L3029 when converting a binary string to integer on a 32bit architecture like armhf.This results in errors like these in the logs:
To Reproduce
The error is showing up in the DEP8 Ubuntu tests at http://autopkgtest.ubuntu.com/packages/cacti. One can see they are failing for armhf: http://autopkgtest.ubuntu.com/packages/cacti/focal/armhf
A simple way to reproduce it is to call the
automation_get_valid_mask()
function with any argument between 0 and 33. For example, 24, on an amd64 machine returns this (with some debugging of mine):On armhf, however:
There are warnings about issues with 32bit architectures on https://www.php.net/manual/en/function.bindec.php and https://www.php.net/manual/en/function.long2ip.php
Expected behavior
On armhf 32bit,
automation_get_valid_mask()
should work properly. For example, return "255.255.255.0" for "subnet" when called with a range == 24.Cacti server
Misc
This is the script I used. I copied the function from
lib/api_automation.php
and added some debugging:The text was updated successfully, but these errors were encountered: