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

(*Transport.)close: nil pointer dereference of handlerMap #3906

Closed
kelmenhorst opened this issue Jun 18, 2023 · 1 comment · Fixed by #3908
Closed

(*Transport.)close: nil pointer dereference of handlerMap #3906

kelmenhorst opened this issue Jun 18, 2023 · 1 comment · Fixed by #3908
Labels
Milestone

Comments

@kelmenhorst
Copy link
Contributor

kelmenhorst commented Jun 18, 2023

Hi,
I noticed that in some cases, (*Transport.)close causes a nil pointer dereference due to (Transport.)handlerMap being uninitialized.

Minimal example to reproduce when using DialEarly:

addr, _ := net.ResolveUDPAddr("udp", "google.com:443")
conn, _ := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0, Zone: ""})
var invalidVersion quic.VersionNumber = 0x3      // <-- there is no v3, so validateConfig will fail
qconf := &quic.Config{
	Versions: []quic.VersionNumber{
		invalidVersion,
	},
}
quic.DialEarly(context.Background(), conn, addr, <*tls.Config>, qconf)

I get the following output:

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=0x30 pc=0x837680]

goroutine 18 [running]:
testing.tRunner.func1.2({0xa96480, 0xffe130})
	/usr/local/go/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1529 +0x39f
panic({0xa96480, 0xffe130})
	/usr/local/go/src/runtime/panic.go:884 +0x213
github.com/quic-go/quic-go.(*Transport).close(0xc0003c41c0, {0xc6d140, 0xc0003943d0})
	/home/kelmenhorst/go/pkg/mod/github.com/quic-go/quic-go@v0.35.1/transport.go:270 +0x100
github.com/quic-go/quic-go.(*Transport).Close(0xc0003c41c0)
	/home/kelmenhorst/go/pkg/mod/github.com/quic-go/quic-go@v0.35.1/transport.go:232 +0x6b
github.com/quic-go/quic-go.DialEarly({0xc73a70, 0xc00003e0b8}, {0xc76620?, 0xc0003960a0?}, {0xc71358, 0xc000392a80}, 0xc0003c0300, 0x55cff4?)
	/home/kelmenhorst/go/pkg/mod/github.com/quic-go/quic-go@v0.35.1/client.go:97 +0x190

Am I missing something here?
If not, I suggest to add a check in (*Transport.)close before trying to close the t.handlerMap.

Edit: Similarly (*Transport.)Close assumes t.conn and t.listening to be initialized which is not always the case (again referring to the example code above).

@marten-seemann
Copy link
Member

Sounds reasonable. Want to submit a patch?

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

Successfully merging a pull request may close this issue.

2 participants