fix: guard NULL/empty edge cases in plugin ordering, tree sort, and SNMP#7177
Closed
somethingwithproof wants to merge 5 commits into
Closed
fix: guard NULL/empty edge cases in plugin ordering, tree sort, and SNMP#7177somethingwithproof wants to merge 5 commits into
somethingwithproof wants to merge 5 commits into
Conversation
cacti_exec() read proc_get_status()['exitcode'] after the child exited. On PHP 8.0-8.2 that field is -1 until proc_close() is called; PHP 8.3 fixed the behaviour. push_out_hosts.php calls cacti_exec() on --help and forwarded the -1 as exit(-1), causing FAILED=4 in the harness. Replace with proc_close(), which returns the correct status on all supported PHP versions. Also fix the --list-host-templates probe: add_device.php is in cli/, not the workspace root. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Line numbers in lib/functions.php shifted by one (single proc_close removed in previous commit), which caused both sink_inventory and architectural_hotspots baselines to diverge. Regenerated both. Replace the single-shot apt-get update/install with a 5-attempt retry loop (20-80s backoff). Acquire::Retries alone does not cover connection- refused failures from the ondrej/php PPA; the outer loop re-runs apt-get update before each package install retry so the index is fresh. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
setup-php already runs apt-get update when it adds the ondrej/php PPA. Running a second update after the PHP install step re-fetches all source lists; if the PPA is temporarily unreachable, apt marks those packages as unavailable and the libapache2-mod-php install fails with E: Unable to fetch packages, even though the packages were already resolvable. Skip the redundant update and install from the cached lists that setup-php left in place. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1.2.x targets PHP 7.4 as its runtime. Testing PHP 8.0-8.4 was out-of-scope and causing flaky failures against the ondrej/php PPA for libapache2-mod-php8.x packages. Narrow the matrix to the one version that matters. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR bundles several unrelated fixes and hardening changes across the Cacti codebase, including null-result guards, conversion of an unsafe SQL builder to prepared statements, an IPv6 SNMP host detection refinement, a proc_close double-call fix, and CI workflow adjustments.
Changes:
- Add null/false guards in
tree.php,lib/plugins.php, and refactorlib/import.phpfield-counter cache update - Convert
REPLACE INTO automation_devicesqueries to prepared statements; tighten IPv6 detection inlib/snmp.php; remove duplicateproc_closeinlib/functions.php - Adjust GitHub Actions syntax workflow (PHP matrix for 1.2.x, apt-get steps,
cli/add_device.phppath) and refresh security baselines
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tree.php | Guard against false return from db_fetch_cell_prepared in two helpers |
| tests/security/baselines/sink_inventory.baseline.tsv | Refresh line numbers in security inventory baseline |
| tests/security/baselines/architectural_hotspots.baseline.tsv | Refresh line numbers in hotspots baseline |
| poller_automation.php | Replace string-concatenated REPLACE queries with db_execute_prepared |
| lib/snmp.php | Bracket only validated IPv6 addresses instead of any string containing a colon |
| lib/plugins.php | Skip plugin id swap when MIN/MAX(id) returns NULL to avoid primary-key corruption |
| lib/import.php | Move generate_data_input_field_sequences call inside the per-field loop using $save['input_string'] |
| lib/functions.php | Remove duplicate proc_close($process) after cacti_exec |
| .github/workflows/syntax.yml | Restrict 1.2.x PHP matrix to 7.4, neutralize apt-get update, fix cli/add_device.php path |
Comment on lines
+2262
to
+2265
| /* update field use counter cache if possible */ | ||
| if (isset($save['input_string']) && $save['input_string'] != '' && $data_input_id > 0) { | ||
| generate_data_input_field_sequences($save['input_string'], $data_input_id); | ||
| } |
Comment on lines
140
to
+141
| - name: Run and apt-get update | ||
| run: sudo apt-get update -o Acquire::Retries=3 || true | ||
| run: true |
| matrix: | ||
| os: [ubuntu-latest] | ||
| php: ${{ fromJSON((github.base_ref == '1.2.x' || github.ref_name == '1.2.x') && '["8.0","8.1","8.2","8.3","8.4"]' || '["8.1","8.2","8.3","8.4"]') }} | ||
| php: ${{ fromJSON((github.base_ref == '1.2.x' || github.ref_name == '1.2.x') && '["7.4"]' || '["8.1","8.2","8.3","8.4"]') }} |
Comment on lines
77
to
79
| if (filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { | ||
| $snmp_hostname = '[' . $hostname . ']'; | ||
| } |
Comment on lines
+319
to
+322
| if ($sort_type === false) { | ||
| return; | ||
| } | ||
|
|
…e device writes api_plugin_moveup()/movedown() skip the reorder when MAX()/MIN() returns NULL on an empty set (avoids a NULL->0 primary-key corruption), tree sort helpers bail when the branch row is missing, and discoverDevices() uses prepared statements for the automation_devices writes. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
ac275c7 to
7d9f71a
Compare
Contributor
Author
|
Closing as redundant: current 1.2.x already contains both the api_plugin_moveup()/movedown() NULL guards and the tree sort-type guards this PR proposed (verified against the 1.2.x tip). Superseded upstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Net-new correctness fixes carried from #7172 (superseded, to be closed):
api_plugin_moveup()/api_plugin_movedown()skip the reorder when MAX()/MIN() returns NULL on an empty set, avoiding a NULL->0 primary-key corruptionfalsecacti_snmp_session()brackets only valid IPv6 literals (filter_var(... FILTER_FLAG_IPV6)) instead of any colon-bearing stringxml_to_data_input_method()regenerates field sequences per fielddiscoverDevices()uses prepared statements for the automation_devices writesBase: 1.2.x.
🤖 Generated with Claude Code