From 7bc0e118317d20974107a8a0f17cf57d400f4791 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 18 Jul 2019 19:34:45 +0200 Subject: device: do not crash on nil'd bind in windows binding --- device/boundif_windows.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'device') diff --git a/device/boundif_windows.go b/device/boundif_windows.go index b842ba8..7879a43 100644 --- a/device/boundif_windows.go +++ b/device/boundif_windows.go @@ -7,6 +7,7 @@ package device import ( "encoding/binary" + "errors" "unsafe" "golang.org/x/sys/windows" @@ -23,6 +24,10 @@ func (device *Device) BindSocketToInterface4(interfaceIndex uint32) error { binary.BigEndian.PutUint32(bytes, interfaceIndex) interfaceIndex = *(*uint32)(unsafe.Pointer(&bytes[0])) + if device.net.bind == nil { + return errors.New("Bind is not yet initialized") + } + sysconn, err := device.net.bind.(*nativeBind).ipv4.SyscallConn() if err != nil { return err -- cgit v1.2.3-59-g8ed1b