Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/textproto: CanonicalMIMEHeaderKey panic on strings with spaces #6712

Closed
bradfitz opened this issue Nov 3, 2013 · 3 comments
Closed

net/textproto: CanonicalMIMEHeaderKey panic on strings with spaces #6712

bradfitz opened this issue Nov 3, 2013 · 3 comments
Milestone

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Nov 3, 2013

CanonicalMIMEHeaderKey panics on certain inputs containing spaces.

Reported from a Google user.

e.g. "C Ontent-Transfer-Encoding" will crash.

I'm getting hg codereview SSL errors now (gogo-inflight SSL MITM?) but fix is here:

diff -r 78cebfb89b21 src/pkg/net/textproto/reader.go
--- a/src/pkg/net/textproto/reader.go   Fri Nov 01 09:18:35 2013 -0700
+++ b/src/pkg/net/textproto/reader.go   Sun Nov 03 13:58:32 2013 -0800
@@ -574,13 +574,10 @@
        // 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 -r 78cebfb89b21 src/pkg/net/textproto/reader_test.go
--- a/src/pkg/net/textproto/reader_test.go  Fri Nov 01 09:18:35 2013 -0700
+++ b/src/pkg/net/textproto/reader_test.go  Sun Nov 03 13:58:32 2013 -0800
@@ -25,6 +25,10 @@
    {"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) {
@bradfitz
Copy link
Contributor Author

bradfitz commented Nov 4, 2013

Comment 1:

Sent https://golang.org/cl/21450043/

Owner changed to @bradfitz.

Status changed to Started.

@bradfitz
Copy link
Contributor Author

bradfitz commented Nov 4, 2013

Comment 2:

This issue was closed by revision 692a147.

Status changed to Fixed.

@adg
Copy link
Contributor

adg commented Nov 13, 2013

Comment 3:

This issue was closed by revision d6a5c861f4e2.

@bradfitz bradfitz self-assigned this Nov 13, 2013
@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
adg added a commit that referenced this issue May 11, 2015
««« 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
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants