http: prevent crash if remote server is not responding with "HTTP/"

Fixes #775.

R=rsc
CC=golang-dev
https://golang.org/cl/1180042
This commit is contained in:
Robert Griesemer 2010-05-11 16:50:20 -07:00
parent 75dbbd2137
commit d6acc0646b

View File

@ -345,7 +345,7 @@ func atoi(s string, i int) (n, i1 int, ok bool) {
// Parse HTTP version: "HTTP/1.2" -> (1, 2, true).
func parseHTTPVersion(vers string) (int, int, bool) {
if vers[0:5] != "HTTP/" {
if len(vers) < 5 || vers[0:5] != "HTTP/" {
return 0, 0, false
}
major, i, ok := atoi(vers, 5)