mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: apply tcp4/tcp6 restrictions to literals in ResolveTCPAddr
The restrictions were already being applied to the IP addresses
received from the host resolver. Apply the same restrictions to
literal IP addresses not passed to the host resolver.
For example, ResolveTCPAddr("tcp4", "[2001:db8::1]:http") used
to succeed and now does not (that's not an IPv4 address).
Perhaps a bit surprisingly,
ResolveTCPAddr("tcp4", "[::ffff:127.0.0.1]:http") succeeds,
behaving identically to ResolveTCPAddr("tcp4", "127.0.0.1:http"), and
ResolveTCPAddr("tcp6", "[::ffff:127.0.0.1]:http") fails,
behaving identically to ResolveTCPAddr("tcp6", "127.0.0.1:http").
Even so, it seems right to match (by reusing) the existing filtering
as applied to addresses resolved by the host C library.
If anyone can make a strong argument for changing the filtering
of IPv4-inside-IPv6 addresses, the fix can be applied to all
the code paths in a separate CL.
Fixes #14037.
Change-Id: I690dfdcbe93d730e11e00ea387fa7484cd524341
Reviewed-on: https://go-review.googlesource.com/32100
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
c4099c7593
commit
866e01457f
6 changed files with 57 additions and 48 deletions
|
|
@ -230,23 +230,27 @@ func TestDialAddrError(t *testing.T) {
|
|||
} {
|
||||
var err error
|
||||
var c Conn
|
||||
var op string
|
||||
if tt.lit != "" {
|
||||
c, err = Dial(tt.network, JoinHostPort(tt.lit, "0"))
|
||||
op = fmt.Sprintf("Dial(%q, %q)", tt.network, JoinHostPort(tt.lit, "0"))
|
||||
} else {
|
||||
c, err = DialTCP(tt.network, nil, tt.addr)
|
||||
op = fmt.Sprintf("DialTCP(%q, %q)", tt.network, tt.addr)
|
||||
}
|
||||
if err == nil {
|
||||
c.Close()
|
||||
t.Errorf("%s %q/%v: should fail", tt.network, tt.lit, tt.addr)
|
||||
t.Errorf("%s succeeded, want error", op)
|
||||
continue
|
||||
}
|
||||
if perr := parseDialError(err); perr != nil {
|
||||
t.Error(perr)
|
||||
t.Errorf("%s: %v", op, perr)
|
||||
continue
|
||||
}
|
||||
aerr, ok := err.(*OpError).Err.(*AddrError)
|
||||
operr := err.(*OpError).Err
|
||||
aerr, ok := operr.(*AddrError)
|
||||
if !ok {
|
||||
t.Errorf("%s %q/%v: should be AddrError: %v", tt.network, tt.lit, tt.addr, err)
|
||||
t.Errorf("%s: %v is %#T, want *AddrError", op, err, operr)
|
||||
continue
|
||||
}
|
||||
want := tt.lit
|
||||
|
|
@ -254,7 +258,7 @@ func TestDialAddrError(t *testing.T) {
|
|||
want = tt.addr.IP.String()
|
||||
}
|
||||
if aerr.Addr != want {
|
||||
t.Fatalf("%s: got %q; want %q", tt.network, aerr.Addr, want)
|
||||
t.Errorf("%s: %v, error Addr=%q, want %q", op, err, aerr.Addr, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue