Skip to content

Commit

Permalink
LibSQL: Report a syntax error for unsupported LIMIT clause syntax
Browse files Browse the repository at this point in the history
Rather than aborting when a LIMIT clause of the form 'LIMIT expr, expr'
is encountered, fail the parser with a syntax error. This will be nicer
for the user and fixes the following fuzzer bug:
https://crbug.com/oss-fuzz/34837
  • Loading branch information
trflynn89 authored and awesomekling committed Jun 3, 2021
1 parent 0ff09d4 commit a870eac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions Tests/LibSQL/TestSqlStatementParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ TEST_CASE(select)
EXPECT(parse("SELECT * FROM table LIMIT 12").is_error());
EXPECT(parse("SELECT * FROM table LIMIT 12 OFFSET;").is_error());
EXPECT(parse("SELECT * FROM table LIMIT 12 OFFSET 15").is_error());
EXPECT(parse("SELECT * FROM table LIMIT 15, 16;").is_error());

struct Type {
SQL::ResultType type;
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibSQL/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ NonnullRefPtr<Select> Parser::parse_select_statement(RefPtr<CommonTableExpressio
RefPtr<Expression> offset_expression;
if (consume_if(TokenType::Offset)) {
offset_expression = parse_expression();
} else {
} else if (consume_if(TokenType::Comma)) {
// Note: The limit clause may instead be defined as "offset-expression, limit-expression", effectively reversing the
// order of the expressions. SQLite notes "this is counter-intuitive" and "to avoid confusion, programmers are strongly
// encouraged to ... avoid using a LIMIT clause with a comma-separated offset."
VERIFY(!consume_if(TokenType::Comma));
syntax_error("LIMIT clauses of the form 'LIMIT <expr>, <expr>' are not supported");
}

limit_clause = create_ast_node<LimitClause>(move(limit_expression), move(offset_expression));
Expand Down

0 comments on commit a870eac

Please sign in to comment.