Skip to content

Commit a92683d

Browse files
ajitpratap0Ajit Pratap Singhclaude
authored
fix: resolve critical nil pointer dereferences in ALTER parser (#101)
* 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 * fix: add nil checks for RENAME COLUMN operations Addresses code review feedback by adding nil checks for both the old column name and new column name in RENAME COLUMN operations. This completes the nil pointer dereference fixes for ALTER TABLE statements by handling all parseIdent() calls that could return nil. Changes: - Added nil check after parseIdent() for old column name (line 91) - Added nil check after parseIdent() for new column name (line 100) - Returns descriptive error messages for missing identifiers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Ajit Pratap Singh <ajitpratapsingh@Ajits-Mac-mini.local> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 265cf4f commit a92683d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pkg/sql/parser/alter.go

Lines changed: 15 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
@@ -82,12 +88,18 @@ func (p *Parser) parseAlterTableStatement(stmt *ast.AlterStatement) (*ast.AlterS
8288
op.Type = ast.RenameColumn
8389
// Convert ast.Identifier to ast.Ident
8490
ident := p.parseIdent()
91+
if ident == nil {
92+
return nil, p.expectedError("column name")
93+
}
8594
op.ColumnName = &ast.Ident{Name: ident.Name}
8695
if !p.matchToken(token.TO) {
8796
return nil, p.expectedError("TO")
8897
}
8998
// Convert ast.Identifier to ast.Ident
9099
newIdent := p.parseIdent()
100+
if newIdent == nil {
101+
return nil, p.expectedError("new column name")
102+
}
91103
op.NewColumnName = &ast.Ident{Name: newIdent.Name}
92104
} else {
93105
return nil, p.expectedError("TO or COLUMN")
@@ -100,6 +112,9 @@ func (p *Parser) parseAlterTableStatement(stmt *ast.AlterStatement) (*ast.AlterS
100112
op.Type = ast.AlterColumn
101113
// Convert ast.Identifier to ast.Ident
102114
ident := p.parseIdent()
115+
if ident == nil {
116+
return nil, p.expectedError("column name")
117+
}
103118
op.ColumnName = &ast.Ident{Name: ident.Name}
104119
colDef, err := p.parseColumnDef()
105120
if err != nil {

0 commit comments

Comments
 (0)