Skip to content

fix: guard against empty firewall policy results to prevent panic - #381

Open
Aprazor wants to merge 1 commit into
prometheus-community:mainfrom
Aprazor:fix/firewall-policy-empty-slice-panic
Open

fix: guard against empty firewall policy results to prevent panic#381
Aprazor wants to merge 1 commit into
prometheus-community:mainfrom
Aprazor:fix/firewall-policy-empty-slice-panic

Conversation

@Aprazor

@Aprazor Aprazor commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

If the FortiOS API returns an empty array (no VDOMs or permission
error), accessing ps4[0] panics with index out of range.

If the FortiOS API returns an empty array (no VDOMs or permission
error), accessing ps4[0] panics with index out of range.

Signed-off-by: Aprazors <Aprazors@gmail.com>
@Aprazor
Aprazor force-pushed the fix/firewall-policy-empty-slice-panic branch from 40e1fbb to 553e190 Compare March 21, 2026 04:54
@bastischubert

Copy link
Copy Markdown
Contributor

Thanks for spotting this! The panic is real, but we'd prefer to fix the root cause: probeFirewallPolicies discards *TargetMetadata (the _ parameter) and re-parses the version from ps4[0] — which is what forces the index access in the first place.

Other probes (bgp_neighbors.go, managed_switch.go, etc.) use meta.VersionMajor/VersionMinor directly. If this probe does the same, ps4[0] is never accessed for version info, the panic becomes impossible by design, and the guard isn't needed.

Would you be open to updating the PR to use meta instead? Happy to help if needed.

@bastischubert

Copy link
Copy Markdown
Contributor

@Aprazor - does that sound ok for you to go the meta route instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants