Commit 2e118812 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: don't crash on Windows when Lookup name has null byte in string

Fixes #31597

Change-Id: I0db1f6f457632c49f9ecfa9d85b99b4cf7d91325
Reviewed-on: https://go-review.googlesource.com/c/go/+/173362
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 17615969
...@@ -1184,3 +1184,13 @@ func TestWithUnexpiredValuesPreserved(t *testing.T) { ...@@ -1184,3 +1184,13 @@ func TestWithUnexpiredValuesPreserved(t *testing.T) {
t.Errorf("Lookup after expiry: Got %v want nil", g) t.Errorf("Lookup after expiry: Got %v want nil", g)
} }
} }
// Issue 31586: don't crash on null byte in name
func TestLookupNullByte(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
testenv.SkipFlakyNet(t)
_, err := LookupHost("foo\x00bar") // used to crash on Windows
if err == nil {
t.Errorf("unexpected success")
}
}
...@@ -101,7 +101,11 @@ func (r *Resolver) lookupIP(ctx context.Context, network, name string) ([]IPAddr ...@@ -101,7 +101,11 @@ func (r *Resolver) lookupIP(ctx context.Context, network, name string) ([]IPAddr
Protocol: syscall.IPPROTO_IP, Protocol: syscall.IPPROTO_IP,
} }
var result *syscall.AddrinfoW var result *syscall.AddrinfoW
e := syscall.GetAddrInfoW(syscall.StringToUTF16Ptr(name), nil, &hints, &result) name16p, err := syscall.UTF16PtrFromString(name)
if err != nil {
return nil, &DNSError{Name: name, Err: err.Error()}
}
e := syscall.GetAddrInfoW(name16p, nil, &hints, &result)
if e != nil { if e != nil {
err := winError("getaddrinfow", e) err := winError("getaddrinfow", e)
dnsError := &DNSError{Err: err.Error(), Name: name} dnsError := &DNSError{Err: err.Error(), Name: name}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment