From 45d96788b5ad98c463671d79f751a042e506663b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 14 Nov 2020 19:52:03 -0800 Subject: [PATCH] net/netns: remove use of unsafe on Windows Found while auditing unsafe for #921 via the list at: https://github.com/tailscale/tailscale/issues/921#issuecomment-727365383 No need for unsafe here, so remove it. --- cmd/tailscale/depaware.txt | 3 ++- cmd/tailscaled/depaware.txt | 3 ++- net/netns/netns_windows.go | 11 ++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index be219a5b0..2d8d8610c 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -56,7 +56,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/net/dnscache from tailscale.com/control/controlclient+ 💣 tailscale.com/net/interfaces from tailscale.com/cmd/tailscale/cli+ tailscale.com/net/netcheck from tailscale.com/cmd/tailscale/cli+ - 💣 tailscale.com/net/netns from tailscale.com/control/controlclient+ + tailscale.com/net/netns from tailscale.com/control/controlclient+ tailscale.com/net/packet from tailscale.com/wgengine+ tailscale.com/net/stun from tailscale.com/net/netcheck+ tailscale.com/net/tlsdial from tailscale.com/control/controlclient+ @@ -76,6 +76,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/types/opt from tailscale.com/control/controlclient+ tailscale.com/types/strbuilder from tailscale.com/net/packet tailscale.com/types/structs from tailscale.com/control/controlclient+ + W tailscale.com/util/endian from tailscale.com/net/netns tailscale.com/util/lineread from tailscale.com/control/controlclient+ tailscale.com/version from tailscale.com/cmd/tailscale/cli+ tailscale.com/version/distro from tailscale.com/cmd/tailscale/cli+ diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index ebe927e35..55d87bdc1 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -61,7 +61,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/net/dnscache from tailscale.com/control/controlclient+ 💣 tailscale.com/net/interfaces from tailscale.com/ipn+ tailscale.com/net/netcheck from tailscale.com/wgengine/magicsock - 💣 tailscale.com/net/netns from tailscale.com/control/controlclient+ + tailscale.com/net/netns from tailscale.com/control/controlclient+ 💣 tailscale.com/net/netstat from tailscale.com/ipn/ipnserver tailscale.com/net/packet from tailscale.com/wgengine+ tailscale.com/net/stun from tailscale.com/net/netcheck+ @@ -84,6 +84,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/opt from tailscale.com/control/controlclient+ tailscale.com/types/strbuilder from tailscale.com/net/packet tailscale.com/types/structs from tailscale.com/control/controlclient+ + W tailscale.com/util/endian from tailscale.com/net/netns tailscale.com/util/lineread from tailscale.com/control/controlclient+ tailscale.com/util/pidowner from tailscale.com/ipn/ipnserver tailscale.com/version from tailscale.com/cmd/tailscaled+ diff --git a/net/netns/netns_windows.go b/net/netns/netns_windows.go index a25b3f22d..9ea475ea1 100644 --- a/net/netns/netns_windows.go +++ b/net/netns/netns_windows.go @@ -5,14 +5,14 @@ package netns import ( - "encoding/binary" + "math/bits" "strings" "syscall" - "unsafe" "golang.org/x/sys/windows" "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" "tailscale.com/net/interfaces" + "tailscale.com/util/endian" ) func interfaceIndex(iface *winipcfg.IPAdapterAddresses) uint32 { @@ -114,7 +114,8 @@ func bindSocket6(c syscall.RawConn, ifidx uint32) error { // representation, suitable for passing to Windows APIs that require a // mangled uint32. func nativeToBigEndian(i uint32) uint32 { - var b [4]byte - binary.BigEndian.PutUint32(b[:], i) - return *(*uint32)(unsafe.Pointer(&b[0])) + if endian.Big { + return i + } + return bits.ReverseBytes32(i) }