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/http: ProxyFromEnvironment panics on malformed no_proxy contents #19536

Closed
calmh opened this issue Mar 13, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@calmh
Copy link
Contributor

commented Mar 13, 2017

In Go 1.8, the following example program:

package main

import (
	"fmt"
	"net/http"
)

func main() {
	cli := http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyFromEnvironment,
		},
	}
	_, err := cli.Get("https://google.com/")
	if err != nil {
		fmt.Println(err)
	}
}

panics on a no_proxy containing a malformed entry:

$ no_proxy=:1 http_proxy=http://127.0.0.1:1234 go run main.go 
panic: runtime error: index out of range

goroutine 1 [running]:
net/http.useProxy(0xc420011100, 0xa, 0xe)
	/usr/local/go/src/net/http/transport.go:1179 +0x48b
net/http.ProxyFromEnvironment(0xc42000a800, 0xc4200110f0, 0xe, 0x18)
	/usr/local/go/src/net/http/transport.go:274 +0xd1
net/http.(*Transport).connectMethodForRequest(0xc4200dc000, 0xc4200ca7e0, 0x0, 0x1263948, 0x5, 0xc4200110f0, 0xe, 0x10, 0xc42004ba50)
	/usr/local/go/src/net/http/transport.go:581 +0x14b
net/http.(*Transport).RoundTrip(0xc4200dc000, 0xc42000a800, 0xc4200dc000, 0x0, 0x0)
	/usr/local/go/src/net/http/transport.go:368 +0x4e6
net/http.send(0xc42000a800, 0x1354b20, 0xc4200dc000, 0x0, 0x0, 0x0, 0x0, 0x8, 0xc42000e048, 0x1010c58)
	/usr/local/go/src/net/http/client.go:249 +0x162
net/http.(*Client).send(0xc420018ea0, 0xc42000a800, 0x0, 0x0, 0x0, 0xc42000e048, 0x0, 0x1, 0xc420018ed0)
	/usr/local/go/src/net/http/client.go:173 +0x108
net/http.(*Client).Do(0xc420018ea0, 0xc42000a800, 0x1263948, 0x13, 0x0)
	/usr/local/go/src/net/http/client.go:595 +0x254
net/http.(*Client).Get(0xc420018ea0, 0x1263948, 0x13, 0xc420018d80, 0xc420018cf0, 0x0)
	/usr/local/go/src/net/http/client.go:393 +0xa7
main.main()
	/Users/jb/src/github.com/calmh/junk/proxypanic/main.go:14 +0xfe
exit status 2

The :1 in no_proxy should have been ::1, but a panic seems inappropriate in any case. Expected results would have been for the request to be proxied (as it did not match any no_proxy entries) or, possibly, return an error indicating that the proxy configuration couldn't be determined.

go version go1.8 darwin/amd64, same problem also present in go1.7.4 so it's not a regression in 1.8.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 13, 2017

CL https://golang.org/cl/38067 mentions this issue.

@bradfitz bradfitz changed the title http: ProxyFromEnvironment panics on malformed no_proxy contents net/http: ProxyFromEnvironment panics on malformed no_proxy contents Mar 14, 2017

@gopherbot gopherbot closed this in 4e35e5f Mar 21, 2017

@golang golang locked and limited conversation to collaborators Mar 21, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.