From 18014f1d9aaf00a1bf538ebc977ef4e745a65e72 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 20 Jul 2023 19:01:05 +0300 Subject: [PATCH] cql3: grammar: reject intValue with no contents The grammar mistakenly allows nothing to be parsed as an intValue (itself accepted in LIMIT and similar clauses). Easily fixed by removing the empty alternative. A unit test is added. Fixes #14705. Closes #14707 (cherry picked from commit e00811caac507aac4ba4a502ef0d820611a3658e) --- cql3/Cql.g | 3 +-- test/cql-pytest/test_bad_grammar.py | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cql3/Cql.g b/cql3/Cql.g index 0f2cea0f2d..d1f36cb022 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -1499,8 +1499,7 @@ marker returns [expression value] ; intValue returns [expression value] - : - | t=INTEGER { $value = untyped_constant{untyped_constant::integer, $t.text}; } + : t=INTEGER { $value = untyped_constant{untyped_constant::integer, $t.text}; } | e=marker { $value = std::move(e); } ; diff --git a/test/cql-pytest/test_bad_grammar.py b/test/cql-pytest/test_bad_grammar.py index c7c8023586..6848f64fae 100644 --- a/test/cql-pytest/test_bad_grammar.py +++ b/test/cql-pytest/test_bad_grammar.py @@ -21,3 +21,10 @@ def table1(cql, test_keyspace): def test_json_empty(cql, table1): with pytest.raises(SyntaxException): cql.execute(f'INSERT INTO {table1} JSON') + +# LIMIT should be followed by an expression (#14705) +def test_limit_empty(cql, table1): + with pytest.raises(SyntaxException): + cql.execute(f'SELECT * FROM {table1} LIMIT') + with pytest.raises(SyntaxException): + cql.execute(f'SELECT * FROM {table1} PER PARTITION LIMIT')