Skip to content

fix: prevent exporter panic on malformed metric lines#12

Open
haydaramru wants to merge 1 commit intohoneynet:mainfrom
haydaramru:fix/prevent-exporter-panic
Open

fix: prevent exporter panic on malformed metric lines#12
haydaramru wants to merge 1 commit intohoneynet:mainfrom
haydaramru:fix/prevent-exporter-panic

Conversation

@haydaramru
Copy link
Copy Markdown

Summary

The handleMetric() function in prometheus/main.go splits incoming metric lines using strings.Fields() and accesses the resulting slice without bounds checks. If a line is malformed or too short (e.g. an empty MQTT topic producing fewer whitespace-delimited fields), this can trigger an index-out-of-range panic and crashing the entire Prometheus exporter, disabling telemetry for all tarpits.

This is the same underlying issue as #8, but the problem is systemic and not limited to SUBSCRIBE:

Case Unguarded access Panics if fields <
connect fields[2] 3
disconnect fields[3] 4
M-SEARCH fields[2] 3
non-M-SEARCH fields[2] 3
CONNECT fields[2] 3
SUBSCRIBE fields[2], fields[3] 4
PUBLISH fields[2], fields[3] 4

The credentials and otherHttpRequests cases already have proper bounds checks and remain unchanged.

Fix: Introduce a top-level guard len(fields) < 2 before accessing fields[0]/fields[1] and per-case guards for higher indices. Malformed lines are now logged and skipped instead of crashing the process.

Resolves #8.

@haydaramru haydaramru force-pushed the fix/prevent-exporter-panic branch from 2654699 to 8981fff Compare March 19, 2026 15:39
@haydaramru haydaramru force-pushed the fix/prevent-exporter-panic branch from 8981fff to 608da39 Compare March 20, 2026 06:39
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.

[Bug] Exporter panics on empty MQTT topic filter

1 participant