mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibSQL: Report a syntax error for unsupported LIMIT clause syntax
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
This commit is contained in:
parent
0ff09d4f74
commit
a870eac0eb
2 changed files with 3 additions and 2 deletions
|
@ -547,6 +547,7 @@ TEST_CASE(select)
|
||||||
EXPECT(parse("SELECT * FROM table LIMIT 12").is_error());
|
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;").is_error());
|
||||||
EXPECT(parse("SELECT * FROM table LIMIT 12 OFFSET 15").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 {
|
struct Type {
|
||||||
SQL::ResultType type;
|
SQL::ResultType type;
|
||||||
|
|
|
@ -321,11 +321,11 @@ NonnullRefPtr<Select> Parser::parse_select_statement(RefPtr<CommonTableExpressio
|
||||||
RefPtr<Expression> offset_expression;
|
RefPtr<Expression> offset_expression;
|
||||||
if (consume_if(TokenType::Offset)) {
|
if (consume_if(TokenType::Offset)) {
|
||||||
offset_expression = parse_expression();
|
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
|
// 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
|
// 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."
|
// 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));
|
limit_clause = create_ast_node<LimitClause>(move(limit_expression), move(offset_expression));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue