Skip to content

Commit

Permalink
Check that IPs are convertible to ipv4
Browse files Browse the repository at this point in the history
If the system receives an IPv6 address, then running the agent with mocks (for example, when running integration tests) can result in panics.

Co-authored-by: Carlos Nihelton <[email protected]>
  • Loading branch information
ashuntu and CarlosNihelton committed Dec 6, 2024
1 parent b4a5f0d commit 8ade7f0
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func getLocalPrivateIP() net.IP {
return nil
}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.IsPrivate() {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.IsPrivate() && ipnet.IP.To4() != nil {
return ipnet.IP
}
}
Expand Down

0 comments on commit 8ade7f0

Please sign in to comment.