diff options
author | Andrew Gerrand <adg@golang.org> | 2013-11-13 14:29:35 +1100 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2013-11-13 14:29:35 +1100 |
commit | 4f8794d3e7079c826d979c55300a3d4036e512f8 (patch) | |
tree | e06e2f2ef7fdc64f463a04d98c0c90097bda267f | |
parent | 065f8fd5a7d910d2a6fed1d26354832500744071 (diff) | |
download | go-4f8794d3e7079c826d979c55300a3d4036e512f8.tar.gz go-4f8794d3e7079c826d979c55300a3d4036e512f8.zip |
[release-branch.go1.2] net/textproto: fix CanonicalMIMEHeaderKey panic
««« CL 21450043 / e081962da65c
net/textproto: fix CanonicalMIMEHeaderKey panic
Fixes #6712
R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/21450043
»»»
R=golang-dev
CC=golang-dev
https://golang.org/cl/25640044
-rw-r--r-- | src/pkg/net/textproto/reader.go | 9 | ||||
-rw-r--r-- | src/pkg/net/textproto/reader_test.go | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/pkg/net/textproto/reader.go b/src/pkg/net/textproto/reader.go index 56ece5b087..b0c07413c1 100644 --- a/src/pkg/net/textproto/reader.go +++ b/src/pkg/net/textproto/reader.go @@ -574,13 +574,10 @@ func canonicalMIMEHeaderKey(a []byte) string { // and upper case after each dash. // (Host, User-Agent, If-Modified-Since). // MIME headers are ASCII only, so no Unicode issues. - if a[i] == ' ' { - a[i] = '-' - upper = true - continue - } c := a[i] - if upper && 'a' <= c && c <= 'z' { + if c == ' ' { + c = '-' + } else if upper && 'a' <= c && c <= 'z' { c -= toLower } else if !upper && 'A' <= c && c <= 'Z' { c += toLower diff --git a/src/pkg/net/textproto/reader_test.go b/src/pkg/net/textproto/reader_test.go index f27042d4e9..cc12912b63 100644 --- a/src/pkg/net/textproto/reader_test.go +++ b/src/pkg/net/textproto/reader_test.go @@ -25,6 +25,10 @@ var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{ {"user-agent", "User-Agent"}, {"USER-AGENT", "User-Agent"}, {"üser-agenT", "üser-Agent"}, // non-ASCII unchanged + + // This caused a panic due to mishandling of a space: + {"C Ontent-Transfer-Encoding", "C-Ontent-Transfer-Encoding"}, + {"foo bar", "Foo-Bar"}, } func TestCanonicalMIMEHeaderKey(t *testing.T) { |