Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topdown/net: require prefix length for IPv6 in net.cidr_merge
There are no default prefixes in IPv6, so if an IPv6 is fed into net.cidr_merge, we'll return a non-halt error now. Before, we'd fail in various ways if a prefix-less IPv6 was fed into `net.cidr_merge`. With only one, we'd return `[ "<nil>" ]`, with two, we'd panic. Fixes #4596. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
- Loading branch information
Showing
3 changed files
with
78 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/cases/testdata/netcidrmerge/test-ipv6-with-and-without-prefix.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
cases: | ||
- note: netcidrmerge/cidr ipv6 with prefix | ||
modules: | ||
- | | ||
package test | ||
p = x { | ||
net.cidr_merge(["2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128"], x) | ||
} | ||
query: data.test.p = x | ||
want_result: | ||
- x: | ||
- "2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128" | ||
- note: netcidrmerge/cidr ipv6 with prefix, same twice | ||
modules: | ||
- | | ||
package test | ||
p = x { | ||
net.cidr_merge(["2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128", "2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128"], x) | ||
} | ||
query: data.test.p = x | ||
want_result: | ||
- x: | ||
- "2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128" | ||
- note: netcidrmerge/cidr ipv6 with prefix, two different prefixes | ||
modules: | ||
- | | ||
package test | ||
p = x { | ||
net.cidr_merge(["2601:600:8a80:207e:a57d:7567:e2c9:e7b3/64", "2601:600:8a80:207e:a57d:7567:e2c9:e7b3/128"], x) | ||
} | ||
query: data.test.p = x | ||
want_result: | ||
- x: | ||
- "2601:600:8a80:207e::/64" | ||
- note: netcidrmerge/cidr ipv6 without prefix | ||
modules: | ||
- | | ||
package test | ||
p = x { | ||
net.cidr_merge(["2601:600:8a80:207e:a57d:7567:e2c9:e7b3"], x) | ||
} | ||
query: data.test.p = x | ||
strict_error: true | ||
want_error: "eval_builtin_error: net.cidr_merge: IPv6 invalid: needs prefix length" | ||
- note: netcidrmerge/cidr ipv6 without prefix, same twice | ||
modules: | ||
- | | ||
package test | ||
p = x { | ||
net.cidr_merge(["2601:600:8a80:207e:a57d:7567:e2c9:e7b3", "2601:600:8a80:207e:a57d:7567:e2c9:e7b3"], x) | ||
} | ||
query: data.test.p = x | ||
strict_error: true | ||
want_error: "eval_builtin_error: net.cidr_merge: IPv6 invalid: needs prefix length" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters