Skip to content

Commit 261fb51

Browse files
committed
[release-branch.go1.15] http/httpguts: remove recursion in HeaderValuesContainsToken
Previously, httpguts.HeaderValuesContainsToken called a function which could recurse to the point of a stack overflow when given a very large header (~10MB). Credit to Guido Vranken who reported the crash as part of the Ethereum 2.0 bounty program. Fixes CVE-2021-31525 Updates golang/go#45710 Updates golang/go#45711 Change-Id: I2c54ce3b2acf1c5efdea66db0595b93a3f5ae5f3 Reviewed-on: https://go-review.googlesource.com/c/net/+/313069 Trust: Katie Hockman <[email protected]> Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> (cherry picked from commit 89ef3d9) Reviewed-on: https://go-review.googlesource.com/c/net/+/314650 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent a5fa9d4 commit 261fb51

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

http/httpguts/httplex.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ func trimOWS(x string) string {
137137
// contains token amongst its comma-separated tokens, ASCII
138138
// case-insensitively.
139139
func headerValueContainsToken(v string, token string) bool {
140-
v = trimOWS(v)
141-
if comma := strings.IndexByte(v, ','); comma != -1 {
142-
return tokenEqual(trimOWS(v[:comma]), token) || headerValueContainsToken(v[comma+1:], token)
140+
for comma := strings.IndexByte(v, ','); comma != -1; comma = strings.IndexByte(v, ',') {
141+
if tokenEqual(trimOWS(v[:comma]), token) {
142+
return true
143+
}
144+
v = v[comma+1:]
143145
}
144-
return tokenEqual(v, token)
146+
return tokenEqual(trimOWS(v), token)
145147
}
146148

147149
// lowerASCII returns the ASCII lowercase version of b.

0 commit comments

Comments
 (0)