golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.54k stars 17.41k forks source link

x/sys/windows: RawSockaddr uses a signed int array for the Data field #41240

Closed ArtificialAmateur closed 3 years ago

ArtificialAmateur commented 3 years ago

What version of Go are you using (go version)?

$ go version
go version go1.15 windows/amd64

Does this issue reproduce with the latest release?

It should as it's still written as is here.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Artificial Amateur\AppData\Local\go-build
set GOENV=C:\Users\Artificial Amateur\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Artificial Amateur\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Artificial Amateur\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=Z:\go-netstat\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ARTIFI~1\AppData\Local\Temp\go-b
uild667920362=/tmp/go-build -gno-record-gcc-switches

What did you do?

Ran windows syscall of GetAdaptersAddresses and printed the value of IpAdapterAddresses.FirstUnicastAddress.Address.Sockaddr.Addr.Data

What did you expect to see?

[0 0 172 16 19 129 0 0 0 0 0 0 0 0]

What did you see instead?

[0 0 -84 16 19 -127 0 0 0 0 0 0 0 0]

This is a minor issue with a simple change of making the Data field of type uint8 or byte.

ArtificialAmateur commented 3 years ago

WinAPI uses a char https://docs.microsoft.com/en-us/windows/win32/winsock/sockaddr-2

I dont agree with it when the other address structs (in_addr) use bytes, but it's the golang code matches.