From ab79599a5ef01ea4015731e01c0348b6b7de0024 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 1 Jun 2021 08:34:51 -0400 Subject: LibSQL: Return an error for empty common table expression lists SQL::CommonTableExpressionList is required to be non-empty. Return an error if zero common table expressions were parsed. Fixes #7627 --- Tests/LibSQL/TestSqlStatementParser.cpp | 2 ++ Userland/Libraries/LibSQL/Parser.cpp | 10 +++++++++- Userland/Libraries/LibSQL/Parser.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Tests/LibSQL/TestSqlStatementParser.cpp b/Tests/LibSQL/TestSqlStatementParser.cpp index 0126a85e4e..64fbe3fb3e 100644 --- a/Tests/LibSQL/TestSqlStatementParser.cpp +++ b/Tests/LibSQL/TestSqlStatementParser.cpp @@ -682,6 +682,8 @@ TEST_CASE(select) TEST_CASE(common_table_expression) { + EXPECT(parse("WITH").is_error()); + EXPECT(parse("WITH;").is_error()); EXPECT(parse("WITH DELETE FROM table;").is_error()); EXPECT(parse("WITH table DELETE FROM table;").is_error()); EXPECT(parse("WITH table AS DELETE FROM table;").is_error()); diff --git a/Userland/Libraries/LibSQL/Parser.cpp b/Userland/Libraries/LibSQL/Parser.cpp index 3e71e1e83f..b12ed59717 100644 --- a/Userland/Libraries/LibSQL/Parser.cpp +++ b/Userland/Libraries/LibSQL/Parser.cpp @@ -23,6 +23,9 @@ NonnullRefPtr Parser::next_statement() if (match(TokenType::With)) { auto common_table_expression_list = parse_common_table_expression_list(); + if (!common_table_expression_list) + return create_ast_node(); + return terminate_statement(parse_statement_with_expression_list(move(common_table_expression_list))); } @@ -331,7 +334,7 @@ NonnullRefPtr parse_select_statement(RefPtr); - NonnullRefPtr parse_common_table_expression_list(); + RefPtr parse_common_table_expression_list(); NonnullRefPtr parse_primary_expression(); NonnullRefPtr parse_secondary_expression(NonnullRefPtr primary); -- cgit v1.2.3