Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ func (p *TextParser) startLabelName() stateFn {
return nil // Unexpected end of input.
}
if p.currentByte == '}' {
if p.currentMF == nil {
// The closing brace was reached before any metric name was read,
// e.g. for the input "{}". There is no metric to attach labels to,
// so this is a malformed exposition. This mirrors the guard in
// startLabelValue. currentMF (not currentMetric) is checked because
// reset only clears currentMF between parses.
p.parseError("invalid metric name")
p.currentLabelPairs = nil
return nil
}
p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPairs...)
p.currentLabelPairs = nil
if p.skipBlankTab(); p.err != nil {
Expand Down
6 changes: 6 additions & 0 deletions expfmt/text_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,12 @@ request_duration_microseconds_count 2693
`,
errUTF8: `text format parsing error in line 5: negative bucket population for histogram "request_duration_microseconds"`,
},
// 47: Empty braces with no metric name (regression test for a nil
// pointer dereference in startLabelName).
{
in: `{} 3.14`,
errUTF8: "text format parsing error in line 1: invalid metric name",
},
}
for i, scenario := range scenarios {
parser.scheme = model.UTF8Validation
Expand Down
Loading