diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cb58ac80e..42f8ca17dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### Features - [#3376](https://github.com/influxdb/influxdb/pull/3376): Support for remote shard query mapping +### Bugfixes +- [#3405](https://github.com/influxdb/influxdb/pull/3405): Prevent database panic when fields are missing. Thanks @jhorwit2 + ## v0.9.2 [unreleased] ### Features diff --git a/tsdb/points.go b/tsdb/points.go index f4cc2a32ed9..d9f4b05bdc5 100644 --- a/tsdb/points.go +++ b/tsdb/points.go @@ -286,6 +286,12 @@ func scanKey(buf []byte, i int) (int, []byte, error) { return i, buf[start:i], fmt.Errorf("invalid tag format") } + // This check makes sure we actually received fields from the user. #3379 + // This will catch invalid syntax such as: `cpu,host=serverA,region=us-west` + if i >= len(buf) { + return i, buf[start:i], fmt.Errorf("missing fields") + } + // Now we know where the key region is within buf, and the locations of tags, we // need to deterimine if duplicate tags exist and if the tags are sorted. This iterates // 1/2 of the list comparing each end with each other, walking towards the center from diff --git a/tsdb/points_test.go b/tsdb/points_test.go index a28e02e0448..dd17b85b95d 100644 --- a/tsdb/points_test.go +++ b/tsdb/points_test.go @@ -150,7 +150,12 @@ func TestParsePointNoValue(t *testing.T) { } func TestParsePointNoFields(t *testing.T) { - _, err := ParsePointsString("cpu") + _, err := ParsePointsString("cpu_load_short,host=server01,region=us-west") + if err == nil { + t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu_load_short,host=server01,region=us-west") + } + + _, err = ParsePointsString("cpu") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu") }