prevent segfault when parsing empty CIDR

This commit is contained in:
Callan Bryant 2020-10-26 22:44:09 +00:00
parent b770d387bf
commit 555ffad58b
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA

View File

@ -18,8 +18,12 @@ func (n JSONIPNet) MarshalJSON() ([]byte, error) {
func (n *JSONIPNet) UnmarshalJSON(b []byte) error {
cidr := strings.Trim(string(b), "\"")
IP, IPNet, err := net.ParseCIDR(cidr)
IPNet.IP = IP
n.IPNet = *IPNet
if err == nil {
IPNet.IP = IP
n.IPNet = *IPNet
}
return err
}