Skip to content

Commit

Permalink
Check that IP is set before parsing
Browse files Browse the repository at this point in the history
Machine is saved to db before it is assigned an ip, so we might have
empty ip fields coming back.
  • Loading branch information
kradalby committed Aug 3, 2021
1 parent eda6e56 commit 73207de
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ func (h *Headscale) getUsedIPs() ([]netaddr.IP, error) {

ips := make([]netaddr.IP, len(addresses))
for index, addr := range addresses {
ip, err := netaddr.ParseIP(addr)
if err != nil {
return nil, fmt.Errorf("failed to parse ip from database, %w", err)
}
if addr != "" {
ip, err := netaddr.ParseIP(addr)
if err != nil {
return nil, fmt.Errorf("failed to parse ip from database, %w", err)
}

ips[index] = ip
ips[index] = ip
}
}

return ips, nil
Expand Down

0 comments on commit 73207de

Please sign in to comment.