Skip to content

Commit

Permalink
http2: correct ServeConnOpts.context's nil receiver check
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aofei authored and bradfitz committed Aug 27, 2019
1 parent 74dc4d7 commit ba9fcec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ type ServeConnOpts struct {
}

func (o *ServeConnOpts) context() context.Context {
if o.Context != nil {
if o != nil && o.Context != nil {
return o.Context
}
return context.Background()
Expand Down
20 changes: 20 additions & 0 deletions http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,26 @@ func (c *issue53Conn) SetDeadline(t time.Time) error { return nil }
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 {
Expand Down

0 comments on commit ba9fcec

Please sign in to comment.