From 2d604ac537c96c13ee9875d2606138178d2defc8 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Wed, 5 Aug 2015 16:41:59 -0600 Subject: [PATCH] Fix panics found via go-fuzz Fixes #3288 --- CHANGELOG.md | 1 + tsdb/points.go | 13 ++++++++++++- tsdb/points_test.go | 24 +++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d68c7c36b5c..9f15a4981b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - [#3414](https://github.com/influxdb/influxdb/issues/3414): Shard mappers perform query re-writing - [#3525](https://github.com/influxdb/influxdb/pull/3525): check if fields are valid during parse time. - [#3511](https://github.com/influxdb/influxdb/issues/3511): Sending a large number of tag causes panic +- [#3288](https://github.com/influxdb/influxdb/issues/3288): Run go fuzz on the line-protocol input ## v0.9.2 [2015-07-24] diff --git a/tsdb/points.go b/tsdb/points.go index 2da241cf759..0f6eb989910 100644 --- a/tsdb/points.go +++ b/tsdb/points.go @@ -117,7 +117,14 @@ func ParsePointsWithPrecision(buf []byte, defaultTime time.Time, precision strin } // lines which start with '#' are comments - if start := skipWhitespace(block, 0); block[start] == '#' { + start := skipWhitespace(block, 0) + + // If line is all whitespace, just skip it + if start >= len(block) { + continue + } + + if block[start] == '#' { continue } @@ -222,6 +229,10 @@ func scanKey(buf []byte, i int) (int, []byte, error) { } if buf[i] == '=' { + if i-1 < 0 || i-2 < 0 { + return i, buf[start:i], fmt.Errorf("missing tag name") + } + // Check for "cpu,=value" but allow "cpu,a\,=value" if buf[i-1] == ',' && buf[i-2] != '\\' { return i, buf[start:i], fmt.Errorf("missing tag name") diff --git a/tsdb/points_test.go b/tsdb/points_test.go index 43a5104eb98..3436408c2e8 100644 --- a/tsdb/points_test.go +++ b/tsdb/points_test.go @@ -147,7 +147,29 @@ func TestParsePointNoValue(t *testing.T) { } if exp := 0; len(pts) != exp { - t.Errorf(`ParsePoints("%s") len mismatch. got %v, exp %vr`, "", len(pts), exp) + t.Errorf(`ParsePoints("%s") len mismatch. got %v, exp %v`, "", len(pts), exp) + } +} + +func TestParsePointWhitespaceValue(t *testing.T) { + pts, err := tsdb.ParsePointsString(" ") + if err != nil { + t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, "", err) + } + + if exp := 0; len(pts) != exp { + t.Errorf(`ParsePoints("%s") len mismatch. got %v, exp %v`, "", len(pts), exp) + } +} + +func TestParsePointSingleEquals(t *testing.T) { + pts, err := tsdb.ParsePointsString("=") + if err == nil { + t.Errorf(`ParsePoints("%s") mismatch. expected error`, "=") + } + + if exp := 0; len(pts) != exp { + t.Errorf(`ParsePoints("%s") len mismatch. got %v, exp %v`, "", len(pts), exp) } }