]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.2] net/textproto: fix CanonicalMIMEHeaderKey panic
authorAndrew Gerrand <adg@golang.org>
Wed, 13 Nov 2013 03:29:35 +0000 (14:29 +1100)
committerAndrew Gerrand <adg@golang.org>
Wed, 13 Nov 2013 03:29:35 +0000 (14:29 +1100)
««« 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

src/pkg/net/textproto/reader.go
src/pkg/net/textproto/reader_test.go

index 56ece5b087c66a5befeda58cc7bb4130d711f486..b0c07413c19dbf23c269cb06e5033fba77e8c568 100644 (file)
@@ -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
index f27042d4e9db881a64a09c355b91de0254c31253..cc12912b634bea67ad0013aeec4838739545fd0d 100644 (file)
@@ -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) {