diff options
| author | Johan Jansson <johan.jansson@iki.fi> | 2022-04-01 14:00:09 +0300 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-04-08 21:40:11 +0000 |
| commit | db576c9f3a33d043b4dc6cd8177f4e0b25ded8ec (patch) | |
| tree | 662cb4ebdd1ff4934312e1c477c5099225ae7ca0 /src/net/textproto/reader.go | |
| parent | 3a19102de3435a3823126e74cf42c67037ff1890 (diff) | |
| download | go-db576c9f3a33d043b4dc6cd8177f4e0b25ded8ec.tar.xz | |
net/textproto: initialize commonHeader in canonicalMIMEHeaderKey
Call initCommonHeader in canonicalMIMEHeaderKey to ensure that
commonHeader is initialized before use. Remove all other calls to
initCommonHeader, since commonHeader is only used in
canonicalMIMEHeaderKey.
This prevents a race condition: read of commonHeader before
commonHeader has been initialized.
Add regression test that triggers the race condition which can be
detected by the race detector.
Fixes #46363
Change-Id: I00c8c52c6f4c78c0305978c876142c1b388174af
Reviewed-on: https://go-review.googlesource.com/c/go/+/397575
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/net/textproto/reader.go')
| -rw-r--r-- | src/net/textproto/reader.go | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/net/textproto/reader.go b/src/net/textproto/reader.go index ac47f00700..65974f9cc2 100644 --- a/src/net/textproto/reader.go +++ b/src/net/textproto/reader.go @@ -28,7 +28,6 @@ type Reader struct { // should be reading from an io.LimitReader or similar Reader to bound // the size of responses. func NewReader(r *bufio.Reader) *Reader { - commonHeaderOnce.Do(initCommonHeader) return &Reader{R: r} } @@ -579,8 +578,6 @@ func (r *Reader) upcomingHeaderNewlines() (n int) { // If s contains a space or invalid header field bytes, it is // returned without modifications. func CanonicalMIMEHeaderKey(s string) string { - commonHeaderOnce.Do(initCommonHeader) - // Quick check for canonical encoding. upper := true for i := 0; i < len(s); i++ { @@ -642,6 +639,7 @@ func canonicalMIMEHeaderKey(a []byte) string { a[i] = c upper = c == '-' // for next time } + commonHeaderOnce.Do(initCommonHeader) // The compiler recognizes m[string(byteSlice)] as a special // case, so a copy of a's bytes into a new string does not // happen in this map lookup: |
