File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -339,6 +339,16 @@ func (p *TextParser) startLabelName() stateFn {
339339 return nil // Unexpected end of input.
340340 }
341341 if p .currentByte == '}' {
342+ if p .currentMF == nil {
343+ // The closing brace was reached before any metric name was read,
344+ // e.g. for the input "{}". There is no metric to attach labels to,
345+ // so this is a malformed exposition. This mirrors the guard in
346+ // startLabelValue. currentMF (not currentMetric) is checked because
347+ // reset only clears currentMF between parses.
348+ p .parseError ("invalid metric name" )
349+ p .currentLabelPairs = nil
350+ return nil
351+ }
342352 p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
343353 p .currentLabelPairs = nil
344354 if p .skipBlankTab (); p .err != nil {
Original file line number Diff line number Diff line change @@ -1332,6 +1332,12 @@ request_duration_microseconds_count 2693
13321332` ,
13331333 errUTF8 : `text format parsing error in line 5: negative bucket population for histogram "request_duration_microseconds"` ,
13341334 },
1335+ // 47: Empty braces with no metric name (regression test for a nil
1336+ // pointer dereference in startLabelName).
1337+ {
1338+ in : `{} 3.14` ,
1339+ errUTF8 : "text format parsing error in line 1: invalid metric name" ,
1340+ },
13351341 }
13361342 for i , scenario := range scenarios {
13371343 parser .scheme = model .UTF8Validation
You can’t perform that action at this time.
0 commit comments