Skip to content

Commit

Permalink
http2: prevent uninitialized pipe from being written
Browse files Browse the repository at this point in the history
For golang/go#65927

Change-Id: I6f48706156384e026968cf9a6d9e0ec76b46fabf
Reviewed-on: https://go-review.googlesource.com/c/net/+/566675
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
panjf2000 authored and neild committed Mar 8, 2024
1 parent ea095bc commit 57a6a7a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion http2/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func (p *pipe) Read(d []byte) (n int, err error) {
}
}

var errClosedPipeWrite = errors.New("write on closed buffer")
var (
errClosedPipeWrite = errors.New("write on closed buffer")
errUninitializedPipeWrite = errors.New("write on uninitialized buffer")
)

// Write copies bytes from p into the buffer and wakes a reader.
// It is an error to write more data than the buffer can hold.
Expand All @@ -91,6 +94,12 @@ func (p *pipe) Write(d []byte) (n int, err error) {
if p.err != nil || p.breakErr != nil {
return 0, errClosedPipeWrite
}
// pipe.setBuffer is never invoked, leaving the buffer uninitialized.
// We shouldn't try to write to an uninitialized pipe,
// but returning an error is better than panicking.
if p.b == nil {
return 0, errUninitializedPipeWrite
}
return p.b.Write(d)
}

Expand Down

0 comments on commit 57a6a7a

Please sign in to comment.