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

Adding a DNAT rule to an Edge Gateway causes a segmentation fault #585

Open
dlipovetsky opened this issue Jun 28, 2023 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@dlipovetsky
Copy link

Describe the bug

I get a segmentation fault when adding a DNAT rule to an Edge Gateway.

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

goroutine 1 [running]:
github.com/vmware/go-vcloud-director/v2/govcd.(*EdgeGateway).AddNATRuleAsync(0xc000017200, {{0x766b93, 0x4}, {0x0, 0x0}, {0x7687a5, 0xa}, {0x0, 0x0}, {0x7687b9, ...}, ...})
	/go/pkg/mod/github.com/vmware/go-vcloud-director/[email protected]/govcd/edgegateway.go:474 +0x365
github.com/vmware/go-vcloud-director/v2/govcd.(*EdgeGateway).AddDNATRule(0xc000017200, {{0x766b93, 0x4}, {0x0, 0x0}, {0x7687a5, 0xa}, {0x0, 0x0}, {0x7687b9, ...}, ...})
	/go/pkg/mod/github.com/vmware/go-vcloud-director/[email protected]/govcd/edgegateway.go:289 +0xc5
main.main()
	main.go:102 +0x458

The root cause appears to be that the AddNATRuleAsync method assumes that EdgeGateway.Configuration.EdgeGatewayServiceConfiguration is not nil, and references its NatService field:

currentEdgeConfig := egw.EdgeGateway.Configuration.EdgeGatewayServiceConfiguration
// Take care of the NAT service
newNatService := &types.NatService{}
if currentEdgeConfig.NatService == nil {
.

Reproduction steps

  1. Add a DNAT rule using this API method
    func (egw *EdgeGateway) AddDNATRule(ruleDetails NatRule) (*types.NatRule, error) {

Expected behavior

A DNAT rule is added to the edge gateway.

Additional context

I have successfully created DNAT rules on the edge gateway using the UI.

VCD version: 10.4.1.21373066
go-vcloud-director version: v2.20.0

@dlipovetsky dlipovetsky added the bug Something isn't working label Jun 28, 2023
@adezxc adezxc self-assigned this Jun 28, 2023
@adezxc
Copy link

adezxc commented Jul 3, 2023

Hi @dlipovetsky,

Thanks for reporting this issue.

You are correct, there is an unchecked condition where the underlying struct is nil. Just to check before creating a fix, could you provide more code that you use for the Edge Gateway as I didn't manage to get a nil structure while fetching one, maybe there are more things to fix in the code.

@dlipovetsky
Copy link
Author

@adezxc Sure! https://github.com/dlipovetsky/dnat-rules-example

Thanks for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants