From 59bbc5c8e3fc64a2720064aec90501bf87099205 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Thu, 1 Oct 2015 20:45:10 -0700 Subject: [PATCH] Reject line protocol that terminates with '-' Fixes issue #4272. --- CHANGELOG.md | 1 + models/points.go | 4 ++++ models/points_test.go | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad52ce157ba..ba2bed39d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - [#4237](https://github.com/influxdb/influxdb/issues/4237): DERIVATIVE() edge conditions - [#4263](https://github.com/influxdb/influxdb/issues/4263): derivative does not work when data is missing - [#4293](https://github.com/influxdb/influxdb/pull/4293): Ensure shell is invoked when touching PID file. Thanks @christopherjdickson +- [#4296](https://github.com/influxdb/influxdb/pull/4296): Reject line protocol ending with '-'. Fixes [#4272](https://github.com/influxdb/influxdb/issues/4272) ## v0.9.4 [2015-09-14] diff --git a/models/points.go b/models/points.go index e709bfffb71..1ded7234d5b 100644 --- a/models/points.go +++ b/models/points.go @@ -560,6 +560,10 @@ func scanNumber(buf []byte, i int) (int, error) { // Is negative number? if i < len(buf) && buf[i] == '-' { i += 1 + // There must be more characters now, as just '-' is illegal. + if i == len(buf) { + return i, fmt.Errorf("invalid number") + } } // how many decimal points we've see diff --git a/models/points_test.go b/models/points_test.go index b86dd875100..1d4d8bf866a 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -412,12 +412,18 @@ func TestParsePointNegativeWrongPlace(t *testing.T) { } } +func TestParsePointOnlyNegativeSign(t *testing.T) { + _, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=-`) + if err == nil { + t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=-`) + } +} + func TestParsePointFloatMultipleDecimals(t *testing.T) { _, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=1.1.1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=1.1.1`) } - println(err.Error()) } func TestParsePointInteger(t *testing.T) {