Skip to content

Commit

Permalink
Fix crash when a prefix family was empty
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Apr 17, 2024
1 parent 4095372 commit c4c8cfe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions hscontrol/db/db.go
Expand Up @@ -377,14 +377,18 @@ func NewHeadscaleDatabase(
}
}

err = tx.Model(&types.Node{}).Where("id = ?", node.ID).Update("ipv4", v4.String()).Error
if err != nil {
return fmt.Errorf("saving ip addresses to new columns: %w", err)
if v4 != nil {
err = tx.Model(&types.Node{}).Where("id = ?", node.ID).Update("ipv4", v4.String()).Error
if err != nil {
return fmt.Errorf("saving ip addresses to new columns: %w", err)
}
}

err = tx.Model(&types.Node{}).Where("id = ?", node.ID).Update("ipv6", v6.String()).Error
if err != nil {
return fmt.Errorf("saving ip addresses to new columns: %w", err)
if v6 != nil {
err = tx.Model(&types.Node{}).Where("id = ?", node.ID).Update("ipv6", v6.String()).Error
if err != nil {
return fmt.Errorf("saving ip addresses to new columns: %w", err)
}
}
}

Expand Down

0 comments on commit c4c8cfe

Please sign in to comment.