Skip to content

fix(parsers.influx): check for nil metric to prevent panic on invalid input#18641

Open
majiayu000 wants to merge 1 commit intoinfluxdata:masterfrom
majiayu000:fix/issue-18228-influx-parser-nil-panic
Open

fix(parsers.influx): check for nil metric to prevent panic on invalid input#18641
majiayu000 wants to merge 1 commit intoinfluxdata:masterfrom
majiayu000:fix/issue-18228-influx-parser-nil-panic

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

Summary

MetricHandler.Metric() panics on input like \\ because the Ragel state machine
completes without error but never calls SetMeasurement(), leaving h.metric nil.
The subsequent h.metric.Time() call dereferences nil and crashes.

Added a nil check in Metric() (handler.go:42-44) so it returns nil instead of
panicking. The caller in parser.go:106-108 already skips nil metrics, so invalid
input just produces no output -- same as other malformed line protocol.

Test added for this case: []byte("\\\\") input, expect no metrics and no error.

  • No AI generated code was used in this PR

Related issues

resolves #18228

… input

When the Ragel state machine completes without calling SetMeasurement(),
h.metric remains nil. Calling Metric() then panics on nil dereference
at h.metric.Time(). Add a nil guard so Metric() returns nil, which
parser.go:106-108 already handles by skipping the entry.

Closes influxdata#18228

Signed-off-by: majiayu000 <1835304752@qq.com>
@telegraf-tiger telegraf-tiger bot added fix pr to fix corresponding bug plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins labels Mar 31, 2026
@telegraf-tiger
Copy link
Copy Markdown
Contributor

@majiayu000 majiayu000 marked this pull request as ready for review March 31, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix pr to fix corresponding bug plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[parsers.influx] invalid input causes telegraf to crash

1 participant