mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
Update to disallow new Go 1.13 float formats. (#5984)
Don't inadvertantly expand the acceptable ways to specify a float. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
parent
b4317768b9
commit
94b1af1471
|
@ -20,7 +20,6 @@ import (
|
|||
"io"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
@ -268,7 +267,7 @@ func (p *OpenMetricsParser) Next() (Entry, error) {
|
|||
if t2 != tValue {
|
||||
return EntryInvalid, parseError("expected value after metric", t)
|
||||
}
|
||||
if p.val, err = strconv.ParseFloat(yoloString(p.l.buf()[1:]), 64); err != nil {
|
||||
if p.val, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
||||
return EntryInvalid, err
|
||||
}
|
||||
// Ensure canonical NaN value.
|
||||
|
@ -283,7 +282,7 @@ func (p *OpenMetricsParser) Next() (Entry, error) {
|
|||
p.hasTS = true
|
||||
var ts float64
|
||||
// A float is enough to hold what we need for millisecond resolution.
|
||||
if ts, err = strconv.ParseFloat(yoloString(p.l.buf()[1:]), 64); err != nil {
|
||||
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
||||
return EntryInvalid, err
|
||||
}
|
||||
p.ts = int64(ts * 1000)
|
||||
|
|
|
@ -370,6 +370,22 @@ func TestOpenMetricsParseErrors(t *testing.T) {
|
|||
input: "empty_label_name{=\"\"} 0",
|
||||
err: "expected label name or left brace, got \"EQUAL\"",
|
||||
},
|
||||
{
|
||||
input: "foo 1_2\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0x1p-3\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0x1P-3\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0 1_2\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
|
|
|
@ -332,7 +332,7 @@ func (p *PromParser) Next() (Entry, error) {
|
|||
if t2 != tValue {
|
||||
return EntryInvalid, parseError("expected value after metric", t)
|
||||
}
|
||||
if p.val, err = strconv.ParseFloat(yoloString(p.l.buf()), 64); err != nil {
|
||||
if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil {
|
||||
return EntryInvalid, err
|
||||
}
|
||||
// Ensure canonical NaN value.
|
||||
|
@ -409,3 +409,11 @@ var helpReplacer = strings.NewReplacer(
|
|||
func yoloString(b []byte) string {
|
||||
return *((*string)(unsafe.Pointer(&b)))
|
||||
}
|
||||
|
||||
func parseFloat(s string) (float64, error) {
|
||||
// Keep to pre-Go 1.13 float formats.
|
||||
if strings.ContainsAny(s, "pP_") {
|
||||
return 0, fmt.Errorf("unsupported character in float")
|
||||
}
|
||||
return strconv.ParseFloat(s, 64)
|
||||
}
|
||||
|
|
|
@ -249,6 +249,22 @@ func TestPromParseErrors(t *testing.T) {
|
|||
input: "empty_label_name{=\"\"} 0",
|
||||
err: "expected label name, got \"EQUAL\"",
|
||||
},
|
||||
{
|
||||
input: "foo 1_2\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0x1p-3\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0x1P-3\n",
|
||||
err: "unsupported character in float",
|
||||
},
|
||||
{
|
||||
input: "foo 0 1_2\n",
|
||||
err: "expected next entry after timestamp, got \"MNAME\"",
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
|
|
Loading…
Reference in a new issue