Skip to content

Commit 319b33a

Browse files
committed
Fix potential nil pointer dereference in primary key parsing
Fixed a potential panic in PostgreSQL primary key constraint parsing by using safe type assertion with the comma-ok idiom instead of an unsafe type assertion. Changes: - Replaced unsafe type assertion with checked type assertion - Added conditional check before accessing String_.Sval - Removed FIXME comment as issue is now resolved This prevents potential runtime panics if key.Node is not actually a *nodes.Node_String_ type, making the code more robust and defensive. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 92e5a24 commit 319b33a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/engine/postgresql/parse.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ func translate(node *nodes.Node) (ast.Node, error) {
418418
case *nodes.Node_Constraint:
419419
if item.Constraint.Contype == nodes.ConstrType_CONSTR_PRIMARY {
420420
for _, key := range item.Constraint.Keys {
421-
// FIXME: Possible nil pointer dereference
422-
primaryKey[key.Node.(*nodes.Node_String_).String_.Sval] = true
421+
if str, ok := key.Node.(*nodes.Node_String_); ok {
422+
primaryKey[str.String_.Sval] = true
423+
}
423424
}
424425
}
425426

0 commit comments

Comments
 (0)