Commit a1600af
committed
expfmt: fix nil pointer panic when parsing empty braces "{}"
The text exposition parser panics with a nil pointer dereference when it
encounters a closing brace before any metric name has been read, e.g. for
the input "{}". In startOfLine a leading "{" sets currentMetricIsInsideBraces
and jumps straight to label parsing without going through readingMetricName,
so currentMF/currentMetric are still nil when startLabelName dereferences
currentMetric on the "}" branch.
Since TextToMetricFamilies is used to decode untrusted scrape payloads, a
malicious or compromised target could crash any consumer that does not wrap
the parser in its own recover().
Guard the "}" branch on currentMF == nil and return a parse error, mirroring
the existing guard in startLabelValue. currentMF is checked rather than
currentMetric because reset only clears currentMF between parses.
Introduced in #670.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>1 parent c7fb7bb commit a1600af
2 files changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
342 | 352 | | |
343 | 353 | | |
344 | 354 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
1335 | 1341 | | |
1336 | 1342 | | |
1337 | 1343 | | |
| |||
0 commit comments