fix: prevent exporter panic on malformed metric lines#12
Open
haydaramru wants to merge 1 commit intohoneynet:mainfrom
Open
fix: prevent exporter panic on malformed metric lines#12haydaramru wants to merge 1 commit intohoneynet:mainfrom
haydaramru wants to merge 1 commit intohoneynet:mainfrom
Conversation
2654699 to
8981fff
Compare
8981fff to
608da39
Compare
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.
Summary
The
handleMetric()function inprometheus/main.gosplits incoming metric lines usingstrings.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:
connectfields[2]disconnectfields[3]M-SEARCHfields[2]non-M-SEARCHfields[2]CONNECTfields[2]SUBSCRIBEfields[2],fields[3]PUBLISHfields[2],fields[3]The
credentialsandotherHttpRequestscases already have proper bounds checks and remain unchanged.Fix: Introduce a top-level guard
len(fields) < 2before accessingfields[0]/fields[1]and per-case guards for higher indices. Malformed lines are now logged and skipped instead of crashing the process.Resolves #8.