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

Fix segfault on invalid CIDR #1377

Merged

Conversation

horazont
Copy link
Contributor

If an invalid CIDR is passed to the subnet resource, for instance
because of a leading space, the plugin will crash:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5b9aa0]

goroutine 101 [running]:
net.networkNumberAndMask(0x20)
        net/ip.go:498
net.(*IPNet).String(0xc00069ed38)
        net/ip.go:548 +0x2b
github.com/terraform-provider-openstack/terraform-provider-openstack/openstack.resourceNetworkingSubnetV2Create({0x10858e8, 0xc000428ea0}, 0xc00061f6c0, {0xef1fa0, 0xc0006a6b40})
        github.com/terraform-provider-openstack/terraform-provider-openstack/openstack/resource_openstack_networking_subnet_v2.go:274 +0x795
[…]

By handling the error and returning it, the crash is avoided and a
proper error message can be displayed by terraform.

If an invalid CIDR is passed to the subnet resource, for instance
because of a leading space, the plugin will crash:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5b9aa0]

goroutine 101 [running]:
net.networkNumberAndMask(0x20)
        net/ip.go:498
net.(*IPNet).String(0xc00069ed38)
        net/ip.go:548 +0x2b
github.com/terraform-provider-openstack/terraform-provider-openstack/openstack.resourceNetworkingSubnetV2Create({0x10858e8, 0xc000428ea0}, 0xc00061f6c0, {0xef1fa0, 0xc0006a6b40})
        github.com/terraform-provider-openstack/terraform-provider-openstack/openstack/resource_openstack_networking_subnet_v2.go:274 +0x795
[…]
```

By handling the error and returning it, the crash is avoided and a
proper error message can be displayed by terraform.
@ozerovandrei ozerovandrei merged commit d39d576 into terraform-provider-openstack:main May 15, 2022
@horazont
Copy link
Contributor Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants