Skip to content

Commit

Permalink
Fix nil pointer error
Browse files Browse the repository at this point in the history
This commit fixes the nil pointer error by adding the dmsg url check in ParseIP().
  • Loading branch information
ersonp committed Nov 29, 2021
1 parent 80c2c47 commit 5548083
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 6 additions & 4 deletions internal/vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,13 @@ func filterOutEqualIPs(ips []net.IP) []net.IP {
ipsSet := make(map[string]struct{})
var filteredIPs []net.IP
for _, ip := range ips {
ipStr := ip.String()
if ip != nil {
ipStr := ip.String()

if _, ok := ipsSet[ipStr]; !ok {
filteredIPs = append(filteredIPs, ip)
ipsSet[ip.String()] = struct{}{}
if _, ok := ipsSet[ipStr]; !ok {
filteredIPs = append(filteredIPs, ip)
ipsSet[ip.String()] = struct{}{}
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion internal/vpn/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package vpn
import (
"fmt"
"net"
"net/url"
"os"
"strconv"
"strings"

"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/dmsgget"
)

const (
Expand Down Expand Up @@ -127,12 +127,24 @@ func IPFromEnv(key string) (net.IP, bool, error) {
// - domain without port;
// - IP with port;
// - IP without port.
// - dmshhttp url with port;
// - dmshhttp url without port.
// In case domain is provided instead of an IP address, a DNS lookup is also
// performed to resolve the actual IP address
func ParseIP(addr string) (net.IP, bool, error) {
if addr == "" {
return nil, false, nil
}
var url dmsgget.URL

// in case dmsghttp url is provided
err := url.Fill(addr)
if url.Scheme == "dmsg" {
if err != nil {
return nil, false, err
}
return nil, true, nil
}

// in case whole URL is passed with the scheme
if strings.Contains(addr, "://") {
Expand Down

0 comments on commit 5548083

Please sign in to comment.