http2: correct ServeConnOpts.context's nil receiver check
Fixes golang/go#33839
Change-Id: Ic1a9e42afc8efda7ec2d39e705efe41474237d82
Reviewed-on: https://go-review.googlesource.com/c/net/+/191857
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/http2/server.go b/http2/server.go
index 5e01ce9..34d4293 100644
--- a/http2/server.go
+++ b/http2/server.go
@@ -322,7 +322,7 @@
}
func (o *ServeConnOpts) context() context.Context {
- if o.Context != nil {
+ if o != nil && o.Context != nil {
return o.Context
}
return context.Background()
diff --git a/http2/server_test.go b/http2/server_test.go
index 5eb16a9..0b77919 100644
--- a/http2/server_test.go
+++ b/http2/server_test.go
@@ -3220,6 +3220,26 @@
func (c *issue53Conn) SetReadDeadline(t time.Time) error { return nil }
func (c *issue53Conn) SetWriteDeadline(t time.Time) error { return nil }
+// golang.org/issue/33839
+func TestServeConnOptsNilReceiverBehavior(t *testing.T) {
+ defer func() {
+ if r := recover(); r != nil {
+ t.Errorf("got a panic that should not happen: %v", r)
+ }
+ }()
+
+ var o *ServeConnOpts
+ if o.context() == nil {
+ t.Error("o.context should not return nil")
+ }
+ if o.baseConfig() == nil {
+ t.Error("o.baseConfig should not return nil")
+ }
+ if o.handler() == nil {
+ t.Error("o.handler should not return nil")
+ }
+}
+
// golang.org/issue/12895
func TestConfigureServer(t *testing.T) {
tests := []struct {