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: call net.ResolveIPAddr with nul char causes a panic in the goroutine on Windows build #31597

Closed
saito-tom opened this issue Apr 21, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@saito-tom
Copy link

commented Apr 21, 2019

What did you do?

My product's server crashed and reproduced the problem from the panic log.
The reproduction program is below.
https://play.golang.org/p/1FdRbei_83s

The reproduction program does not work on Go Playground. Create a windows build and run it.

What did you expect to see?

I wanted to return an error if an invalid string is passed.

addr:  127.0.0.1
err: lookup localhost: no such host

What did you see instead?

Output of Windows build binary (GOOS=windows go run resolve_ip.go)

0032:fixme:process:SetProcessPriorityBoost (0xffffffffffffffff,1): stub
addr:  127.0.0.1
panic: syscall: string with NUL passed to StringToUTF16

goroutine 6 [running]:
syscall.StringToUTF16(...)
        /home/st/Downloads/go/src/syscall/syscall_windows.go:30
syscall.StringToUTF16Ptr(0x4f03b7, 0xa, 0x0)
        /home/st/Downloads/go/src/syscall/syscall_windows.go:65 +0x8b
net.(*Resolver).lookupIP.func1(0x0, 0x0, 0x0, 0x0, 0x0)
        /home/st/Downloads/go/src/net/lookup_windows.go:99 +0xf1
net.(*Resolver).lookupIP.func2(0xc000004100, 0xc00003c240)
        /home/st/Downloads/go/src/net/lookup_windows.go:129 +0x32
created by net.(*Resolver).lookupIP
        /home/st/Downloads/go/src/net/lookup_windows.go:128 +0xf8
exit status 2

Output of Linux build binary (go run resolve_ip.go)

addr:  127.0.0.1
err: lookup localhost: no such host

System details

go version go1.12.4 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/st/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/st/go"
GOPROXY=""
GORACE=""
GOROOT="/home/st/Downloads/go"
GOTMPDIR=""
GOTOOLDIR="/home/st/Downloads/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
uname -sr: Linux 4.19.32-1-MANJARO
LSB Version:	n/a
Distributor ID:	ManjaroLinux
Description:	Manjaro Linux
Release:	18.0.4
Codename:	Illyria
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.28.
gdb --version: GNU gdb (GDB) 8.2.1
@saito-tom

This comment has been minimized.

Copy link
Author

commented Apr 21, 2019

In lookupIP, it seems like it is not good to call Deprecated syscall.StringToUTF16Ptr which causes panic.

lookupIP:

e := syscall.GetAddrInfoW(syscall.StringToUTF16Ptr(name), nil, &hints, &result)

syscall.StringToUTF16Ptr:

// Deprecated: Use UTF16PtrFromString instead.
func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }

// Deprecated: Use UTF16FromString instead.
func StringToUTF16(s string) []uint16 {
a, err := UTF16FromString(s)
if err != nil {
panic("syscall: string with NUL passed to StringToUTF16")
}
return a

@julieqiu julieqiu added this to the Go1.13 milestone Apr 22, 2019

@julieqiu

This comment has been minimized.

Copy link

commented Apr 22, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Apr 23, 2019

Change https://golang.org/cl/173362 mentions this issue: net: don't crash on Windows when Lookup name has null byte in string

@gopherbot gopherbot closed this in 2e11881 Apr 23, 2019

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