diff --git a/influxql/parser.go b/influxql/parser.go index b235dad11b..35fd28dada 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -490,6 +490,10 @@ func (p *Parser) parseLimit() (int, error) { // Parse number. n, _ := strconv.ParseInt(lit, 10, 64) + if n < 1 { + return 0, &ParseError{Message: "limit must be > 0", Pos: pos} + } + return int(n), nil } diff --git a/influxql/parser_test.go b/influxql/parser_test.go index f22d5306ce..5e38a70768 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -212,6 +212,7 @@ func TestParser_ParseStatement(t *testing.T) { {s: `SELECT field1 FROM myseries GROUP`, err: `found EOF, expected BY at line 1, char 35`}, {s: `SELECT field1 FROM myseries LIMIT`, err: `found EOF, expected number at line 1, char 35`}, {s: `SELECT field1 FROM myseries LIMIT 10.5`, err: `fractional parts not allowed in limit at line 1, char 35`}, + {s: `SELECT field1 FROM myseries LIMIT 0`, err: `limit must be > 0 at line 1, char 35`}, {s: `SELECT field1 FROM myseries ORDER`, err: `found EOF, expected BY at line 1, char 35`}, {s: `SELECT field1 FROM myseries ORDER BY /`, err: `found /, expected identifier, ASC, or DESC at line 1, char 38`}, {s: `SELECT field1 FROM myseries ORDER BY 1`, err: `found 1, expected identifier, ASC, or DESC at line 1, char 38`},