Skip to content

Commit d7e4f6c

Browse files
ck319huntergregory
andauthored
fix: [NPM] add check for invalid /0 cidr (#1739)
* add check for invalid /0 cidr * added UT for valid cidr --------- Co-authored-by: Hunter Gregory <[email protected]>
1 parent 60fcc5c commit d7e4f6c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

npm/pkg/dataplane/ipsets/ipsetmanager_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,16 @@ func TestValidateIPSetMemberIP(t *testing.T) {
15461546
ipblock: "2345:0425:2CA1:0000:0000:0567:5673:23b5 nomatch",
15471547
want: false,
15481548
},
1549+
{
1550+
name: "invalid/0",
1551+
ipblock: "1.1.1.1/0",
1552+
want: false,
1553+
},
1554+
{
1555+
name: "valid/0",
1556+
ipblock: "0.0.0.0/0",
1557+
want: true,
1558+
},
15491559
}
15501560

15511561
for _, tt := range tests {

npm/util/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ func SliceToString(list []string) string {
322322
func IsIPV4(ip string) bool {
323323
isIPBlock := strings.Contains(ip, "/")
324324
ipOnly := strings.Split(ip, "/")
325+
if strings.Contains(ip, "/0") && ipOnly[0] != "0.0.0.0" {
326+
return false
327+
}
328+
325329
address, err := netip.ParseAddr(ipOnly[0])
326330
if err != nil {
327331
return false

0 commit comments

Comments
 (0)