From dd0cc746881d75da6eebe0615fb1c477d59bd3a2 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Wed, 17 Apr 2024 13:23:29 +0000 Subject: [PATCH] Fix crash when a prefix family was empty --- hscontrol/db/db.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index e54ea19f..c8ec3378 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -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) + } } }