Skip to content

Commit 59ca318

Browse files
Ajit Pratap SinghAjit Pratap Singh
authored andcommitted
fix: resolve critical nil pointer dereferences in ALTER parser
Fixes three critical nil pointer dereference bugs discovered during comprehensive error recovery testing: 1. ALTER TABLE DROP COLUMN - missing column name check (line 61) 2. ALTER TABLE DROP CONSTRAINT - missing constraint name check (line 72) 3. ALTER TABLE ALTER COLUMN - missing column name check (line 109) All three cases now properly check if parseIdent() returns nil before accessing the Name field, returning appropriate error messages instead of crashing. These bugs would have caused production crashes when parsing invalid ALTER statements missing required identifier tokens. Fixes issues discovered in TEST-013: Parser Error Recovery Tests
1 parent 265cf4f commit 59ca318

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/sql/parser/alter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func (p *Parser) parseAlterTableStatement(stmt *ast.AlterStatement) (*ast.AlterS
5858
op.Type = ast.DropColumn
5959
// Convert ast.Identifier to ast.Ident
6060
ident := p.parseIdent()
61+
if ident == nil {
62+
return nil, p.expectedError("column name")
63+
}
6164
op.ColumnName = &ast.Ident{Name: ident.Name}
6265
if p.matchToken(token.CASCADE) {
6366
op.CascadeDrops = true
@@ -66,6 +69,9 @@ func (p *Parser) parseAlterTableStatement(stmt *ast.AlterStatement) (*ast.AlterS
6669
op.Type = ast.DropConstraint
6770
// Convert ast.Identifier to ast.Ident
6871
ident := p.parseIdent()
72+
if ident == nil {
73+
return nil, p.expectedError("constraint name")
74+
}
6975
op.ConstraintName = &ast.Ident{Name: ident.Name}
7076
if p.matchToken(token.CASCADE) {
7177
op.CascadeDrops = true
@@ -100,6 +106,9 @@ func (p *Parser) parseAlterTableStatement(stmt *ast.AlterStatement) (*ast.AlterS
100106
op.Type = ast.AlterColumn
101107
// Convert ast.Identifier to ast.Ident
102108
ident := p.parseIdent()
109+
if ident == nil {
110+
return nil, p.expectedError("column name")
111+
}
103112
op.ColumnName = &ast.Ident{Name: ident.Name}
104113
colDef, err := p.parseColumnDef()
105114
if err != nil {

0 commit comments

Comments
 (0)