Skip to content

Commit 3f5e89d

Browse files
authored
bug: fix a crash with an invalid query following MODIFY QUERY (#215)
ALTER TABLE foo MODIFY QUERY <an invalid query> crashed the parser with a sigsegv due to a missing error check; this commit adds the missing check and a regression test.
1 parent 4466b5c commit 3f5e89d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

parser/parser_alter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,10 @@ func (p *Parser) parseAlterTableModify(pos Pos) (AlterTableClause, error) {
648648
}, nil
649649
case p.matchKeyword(KeywordQuery):
650650
_ = p.lexer.consumeToken()
651-
selectQuery, _ := p.parseSelectQuery(pos)
651+
selectQuery, err := p.parseSelectQuery(pos)
652+
if err != nil {
653+
return nil, err
654+
}
652655
return &AlterTableModifyQuery{
653656
ModifyPos: pos,
654657
StatementEnd: selectQuery.End(),

parser/parser_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func TestParser_InvalidSyntax(t *testing.T) {
140140
"SELECT n FROM t ORDER BY n WITH FILL STALENESS", // STALENESS without value
141141
"SELECT n FROM t ORDER BY n WITH FILL INTERPOLATE (x", // Missing closing paren
142142
"SELECT n FROM t ORDER BY n WITH FILL INTERPOLATE x AS x + 1", // Missing parens around column list
143+
"ALTER TABLE foo_mv MODIFY QUERY AS SELECT * FROM baz", // MODIFY QUERY followed by an invalid query
143144
}
144145
for _, sql := range invalidSQLs {
145146
parser := NewParser(sql)

0 commit comments

Comments
 (0)