Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit a452640

Browse files
committed
Fuzz IP.Is<property>() methods against stdlib net.IP equivalents
The intent is to find discrepancies between netaddr.IP and net.IP. These don't necessarily indicate a bug (in either), but it's better to find them and explicitly document/exclude them.
1 parent d57edf1 commit a452640

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

fuzz.go

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ func Fuzz(b []byte) int {
4343
panic(".Prior.Next did not round trip")
4444
}
4545

46+
// Check that we agree with the standard library wrt to poperties
47+
if !strings.Contains(s, "%") {
48+
stdip := net.ParseIP(s)
49+
tests := []struct {
50+
name string
51+
ipResult bool
52+
stdipResult bool
53+
}{
54+
{"IsInterfaceLocalMulticast", ip.IsInterfaceLocalMulticast(), stdip.IsInterfaceLocalMulticast()},
55+
{"IsLinkLocalMulticast", ip.IsLinkLocalMulticast(), stdip.IsLinkLocalMulticast()},
56+
{"IsLinkLocalUnicast", ip.IsLinkLocalUnicast(), stdip.IsLinkLocalUnicast()},
57+
{"IsLoopback", ip.IsLoopback(), stdip.IsLoopback()},
58+
{"IsMulticast", ip.IsMulticast(), stdip.IsMulticast()},
59+
}
60+
61+
for _, tt := range tests {
62+
if tt.ipResult != tt.stdipResult {
63+
fmt.Printf("net.IP=%#v .%v=%v, netaddr.IP=%#v %v=%v\n", stdip, tt.name, tt.stdipResult, ip, tt.name, tt.ipResult)
64+
panic(fmt.Sprintf(".%v() did not agree with stdlib", tt.name))
65+
}
66+
}
67+
}
68+
4669
port, err := ParseIPPort(s)
4770
if err == nil {
4871
checkStringParseRoundTrip(port, parseIPPort)

0 commit comments

Comments
 (0)