Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cidrnetmask() produce an error with IPv6 #30703

Merged
merged 3 commits into from Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/lang/funcs/cidr.go
Expand Up @@ -60,6 +60,10 @@ var CidrNetmaskFunc = function.New(&function.Spec{
return cty.UnknownVal(cty.String), fmt.Errorf("invalid CIDR expression: %s", err)
}

if network.IP.To4() == nil {
return cty.UnknownVal(cty.String), fmt.Errorf("IPv6 is invalid")
shinbunbun marked this conversation as resolved.
Show resolved Hide resolved
}

return cty.StringVal(ipaddr.IP(network.Mask).String()), nil
},
})
Expand Down
10 changes: 5 additions & 5 deletions internal/lang/funcs/cidr_test.go
Expand Up @@ -118,11 +118,6 @@ func TestCidrNetmask(t *testing.T) {
cty.StringVal("0.0.0.0"),
false,
},
{
cty.StringVal("1::/64"),
cty.StringVal("ffff:ffff:ffff:ffff::"),
false,
},
{
// We inadvertently inherited a pre-Go1.17 standard library quirk
// if parsing zero-prefix parts as decimal rather than octal.
Expand All @@ -144,6 +139,11 @@ func TestCidrNetmask(t *testing.T) {
cty.UnknownVal(cty.String),
true, // can't have an octet >255
},
{
cty.StringVal("1::/64"),
cty.UnknownVal(cty.String),
true, // IPv6 is invalid
},
}

for _, test := range tests {
Expand Down