Skip to content

Commit 4f8794d

Browse files
committed
[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
1 parent 065f8fd commit 4f8794d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/pkg/net/textproto/reader.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,10 @@ func canonicalMIMEHeaderKey(a []byte) string {
574574
// and upper case after each dash.
575575
// (Host, User-Agent, If-Modified-Since).
576576
// MIME headers are ASCII only, so no Unicode issues.
577-
if a[i] == ' ' {
578-
a[i] = '-'
579-
upper = true
580-
continue
581-
}
582577
c := a[i]
583-
if upper && 'a' <= c && c <= 'z' {
578+
if c == ' ' {
579+
c = '-'
580+
} else if upper && 'a' <= c && c <= 'z' {
584581
c -= toLower
585582
} else if !upper && 'A' <= c && c <= 'Z' {
586583
c += toLower

src/pkg/net/textproto/reader_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{
2525
{"user-agent", "User-Agent"},
2626
{"USER-AGENT", "User-Agent"},
2727
{"üser-agenT", "üser-Agent"}, // non-ASCII unchanged
28+
29+
// This caused a panic due to mishandling of a space:
30+
{"C Ontent-Transfer-Encoding", "C-Ontent-Transfer-Encoding"},
31+
{"foo bar", "Foo-Bar"},
2832
}
2933

3034
func TestCanonicalMIMEHeaderKey(t *testing.T) {

0 commit comments

Comments
 (0)