aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/fs_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2019-01-23 19:09:07 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2019-01-23 19:31:46 +0000
commit829c5df58694b3345cb5ea41206783c8ccf5c3ca (patch)
treed00f25105998b1febceffce61fe9db56485b8963 /src/net/http/fs_test.go
parent4edea0f0a77b341ec565d848e453c4a854418e8c (diff)
downloadgo-829c5df58694b3345cb5ea41206783c8ccf5c3ca.tar.xz
net/url, net/http: reject control characters in URLs
This is a more conservative version of the reverted CL 99135 (which was reverted in CL 137716) The net/url part rejects URLs with ASCII CTLs from being parsed and the net/http part rejects writing them if a bogus url.URL is constructed otherwise. Updates #27302 Updates #22907 Change-Id: I09a2212eb74c63db575223277aec363c55421ed8 Reviewed-on: https://go-review.googlesource.com/c/159157 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
Diffstat (limited to 'src/net/http/fs_test.go')
-rw-r--r--src/net/http/fs_test.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
index 255d215f3c..762e88b05f 100644
--- a/src/net/http/fs_test.go
+++ b/src/net/http/fs_test.go
@@ -583,16 +583,23 @@ func TestFileServerZeroByte(t *testing.T) {
ts := httptest.NewServer(FileServer(Dir(".")))
defer ts.Close()
- res, err := Get(ts.URL + "/..\x00")
+ c, err := net.Dial("tcp", ts.Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
- b, err := ioutil.ReadAll(res.Body)
+ defer c.Close()
+ _, err = fmt.Fprintf(c, "GET /..\x00 HTTP/1.0\r\n\r\n")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var got bytes.Buffer
+ bufr := bufio.NewReader(io.TeeReader(c, &got))
+ res, err := ReadResponse(bufr, nil)
if err != nil {
- t.Fatal("reading Body:", err)
+ t.Fatal("ReadResponse: ", err)
}
if res.StatusCode == 200 {
- t.Errorf("got status 200; want an error. Body is:\n%s", string(b))
+ t.Errorf("got status 200; want an error. Body is:\n%s", got.Bytes())
}
}