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 NRE Panic in dialSCTPExtConfig and listenSCTPExtConfig when control is used #68

Merged
merged 2 commits into from
Feb 9, 2025

Conversation

paulrozhkin
Copy link

Description

This PR fixes a nil reference panic that occurs in dialSCTPExtConfig and listenSCTPExtConfig when the control function is passed and laddr is nil (SCTP use without SCTP_SOCKOPT_BINDX_ADD).
The issue was caused by calling laddr.String() without checking for nil.

Panic Stacktrace:

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

goroutine 6 [running]:
testing.tRunner.func1.2({0x55b2a0, 0x695fc0})
	/usr/local/go/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1529 +0x39f
panic({0x55b2a0, 0x695fc0})
	/usr/local/go/src/runtime/panic.go:884 +0x213
github.com/ishidawataru/sctp.(*SCTPAddr).String(0x0)

Fix

Added a nil check before accessing laddr.String() in both functions. Pass an empty string to the control function:

var localAddressString string  
if laddr != nil {  
    localAddressString = laddr.String()  
}
if err = control(network, localAddressString, rc); err != nil {
    return nil, err
}

@ishidawataru ishidawataru merged commit bfe71a1 into ishidawataru:master Feb 9, 2025
3 checks passed
@ishidawataru
Copy link
Owner

Thanks!

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.

2 participants