Skip to content

Commit 4ab3c10

Browse files
awen09Bryan C. Mills
authored and
Bryan C. Mills
committed
cmd/go/internal/web: improve IP check testing on ipv6 env
The existing implementation lacks consideration of running test on a machine which has ipv6 address but no ipv4 address. Use net.IP.IsLoopback and net.IP.IsUnspecified instead of hardcoded addresses. Fixes: #48575 This PR will be imported into Gerrit with the title and first comment (this text) used to generate the subject and body of the Gerrit change. Change-Id: I9c3c26d2ba13c7a24065751b59a1e002098ed654 GitHub-Last-Rev: fc45adb GitHub-Pull-Request: #48850 Reviewed-on: https://go-review.googlesource.com/c/go/+/354609 Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Jay Conrod <[email protected]>
1 parent 7286502 commit 4ab3c10

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/cmd/go/internal/web/http.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"errors"
1818
"fmt"
1919
"mime"
20+
"net"
2021
"net/http"
2122
urlpkg "net/url"
2223
"os"
@@ -84,8 +85,15 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
8485
if url.Host == "localhost.localdev" {
8586
return nil, fmt.Errorf("no such host localhost.localdev")
8687
}
87-
if os.Getenv("TESTGONETWORK") == "panic" && !strings.HasPrefix(url.Host, "127.0.0.1") && !strings.HasPrefix(url.Host, "0.0.0.0") {
88-
panic("use of network: " + url.String())
88+
if os.Getenv("TESTGONETWORK") == "panic" {
89+
host := url.Host
90+
if h, _, err := net.SplitHostPort(url.Host); err == nil && h != "" {
91+
host = h
92+
}
93+
addr := net.ParseIP(host)
94+
if addr == nil || (!addr.IsLoopback() && !addr.IsUnspecified()) {
95+
panic("use of network: " + url.String())
96+
}
8997
}
9098

9199
fetch := func(url *urlpkg.URL) (*urlpkg.URL, *http.Response, error) {

0 commit comments

Comments
 (0)