Bug #15190
closedPHP error from RRD Graphs when resolution is null
100%
Description
Happens on
23.09.1-RELEASE (amd64) built on Wed Dec 20 13:27:00 EST 2023 FreeBSD 14.0-CURRENT
[25-Jan-2024 00:58:45 US/Mountain] PHP Fatal error: Uncaught TypeError: Unsupported operand types: string - null in /usr/local/www/rrd_fetch_json.php:149 Stack trace: #0 {main} thrown in /usr/local/www/rrd_fetch_json.php on line 149
I am attempting to reproduce the error. The line in question is "$end -= $resolution;"
The error indicates $resolution is null. A check to verify the value is sane is a simple fix.
Files
Updated by Christopher Cope 10 months ago
More information: The code is being hit when using the custom Time Period. The code attempts to subtract the resolution from the end date, to prevent the 0 value at the end, but the resolution variable is null. I am able to reproduce the error by clearing the RRD and attempting to use the custom Time Period. It is also possible to trigger it by selecting None on both the left and right axis.
Updated by Christopher Cope 10 months ago
- Status changed from New to Pull Request Review
Updated by Danilo Zrenjanin 10 months ago
I can reproduce the issue on the:
23.09.1-RELEASE (amd64) built on Wed Dec 6 20:22:00 UTC 2023 FreeBSD 14.0-CURRENT
Crash report begins. Anonymous machine information: amd64 15.0-CURRENT FreeBSD 15.0-CURRENT #0 plus-devel-main-n256255-225fbd24aea: Thu Feb 1 16:42:44 UTC 2024 root@freebsd:/var/jenkins/workspace/pfSense-Plus-snapshots-master-main/obj/amd64/I2zxDaYf/var/jenkins/workspace/pfSense-Plus-snapshots-master-main/sources/FreeBS Crash report details: PHP Errors: [03-Feb-2024 08:07:08 Etc/UTC] PHP Fatal error: Uncaught TypeError: Unsupported operand types: string - null in /usr/local/www/rrd_fetch_json.php:149 Stack trace: #0 {main} thrown in /usr/local/www/rrd_fetch_json.php on line 149 No FreeBSD crash data found.
Updated by Danilo Zrenjanin 10 months ago
I'll wait for Jim's advise to be considered before testing the patch.
Updated by Jim Pingle 10 months ago
The change should be OK to test, though since this is a patch in the ports tree you'll need to copy paste the diff and either change the path strip value or alter the paths in the diff, plus remove the Makefile change.
For example, just test this diff instead of the whole MR diff:
diff --git a/a/usr/local/www/rrd_fetch_json.php b/b/usr/local/www/rrd_fetch_json.php
index 43a469b52e56f0a8b62fce548e4c5839ac6c8b28..ff93b1c7a22aca16f7261bd81753aa32d97573d7 100644
--- a/a/usr/local/www/rrd_fetch_json.php
+++ b/b/usr/local/www/rrd_fetch_json.php
@@ -140,7 +140,7 @@ if ($timePeriod === "custom") {
$right_rrd_array = array();
}
- $resolution = max($left_rrd_array['step'], $right_rrd_array['step']);
+ $resolution = (int) max($left_rrd_array['step'], $right_rrd_array['step']);
// make sure end time isn't later than last updated time entry
if ( $end > $last_updated ) { $end = $last_updated; }
Updated by Jim Pingle 10 months ago
- Status changed from Pull Request Review to Feedback
- Target version set to 2.8.0
- % Done changed from 0 to 100
- Plus Target Version set to 24.03
MR merged.
Updated by Danilo Zrenjanin 10 months ago
I tested the patch against:
24.03-DEVELOPMENT (amd64) built on Mon Feb 5 6:00:00 UTC 2024 FreeBSD 15.0-CURRENT
After clicking the "Update Graphs" button, a PHP error occurs. Please refer to the provided screenshot for the setup causing the issue.
Updated by Christopher Cope 10 months ago
Danilo Zrenjanin wrote in #note-8:
I tested the patch against:
[...]
After clicking the "Update Graphs" button, a PHP error occurs. Please refer to the provided screenshot for the setup causing the issue.
I am seeing an error also with those options. It's because the start and end dates aren't defined and therefore end is a string. That should be checked as well, and it seems a similar issue was also occurring in the original error. It may also make sense to add error checking to not let a user submit it without filling in the dates.
PHP ERROR: Type: 1, File: /usr/local/www/rrd_fetch_json.php, Line: 149, Message: Uncaught TypeError: Unsupported operand types: string - int in /usr/local/www/rrd_fetch_json.php:149 Stack trace:
Updated by Christopher Cope 9 months ago
- Status changed from Feedback to Pull Request Review
Updated by Danilo Zrenjanin 9 months ago
- Status changed from Feedback to Resolved
It works fine on today's release:
I will close this ticket as resolved.