aboutsummaryrefslogtreecommitdiff
path: root/tun/wintun/setupapi/setupapi_windows.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-04-18 10:37:04 +0200
committerSimon Rozman <simon@rozman.si>2019-04-18 10:39:22 +0200
commit5811447b382ce1197e9c76d676a65515309a5b60 (patch)
treeb0a5ed9d7d8faa6cc5edf7b2d6c05d265125b8a2 /tun/wintun/setupapi/setupapi_windows.go
parente0a8c22aa64d6a606cb03e3fd09eaa3e62a2f7c9 (diff)
downloadwireguard-go-5811447b382ce1197e9c76d676a65515309a5b60.tar.gz
wireguard-go-5811447b382ce1197e9c76d676a65515309a5b60.zip
setupapi: Revise DrvInfoDetailData struct size calculation
Go adds trailing padding to DrvInfoDetailData struct in GOARCH=386 which confuses SetupAPI expecting exactly sizeof(SP_DRVINFO_DETAIL_DATA). Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun/setupapi/setupapi_windows.go')
-rw-r--r--tun/wintun/setupapi/setupapi_windows.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/tun/wintun/setupapi/setupapi_windows.go b/tun/wintun/setupapi/setupapi_windows.go
index 71732a4..1731f4b 100644
--- a/tun/wintun/setupapi/setupapi_windows.go
+++ b/tun/wintun/setupapi/setupapi_windows.go
@@ -155,7 +155,10 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
var bufLen uint32
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
- data.size = uint32(unsafe.Sizeof(*data))
+
+ // unsafe.Sizeof(data) >= sizeof(SP_DRVINFO_DETAIL_DATA) due to Go trailing padding. SetupAPI expects exactly sizeof(SP_DRVINFO_DETAIL_DATA).
+ sizeAPI := unsafe.Offsetof(data.hardwareID) + unsafe.Sizeof(data.hardwareID)
+ data.size = uint32(sizeAPI)
err := setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufCapacity, &bufLen)
if err == nil {
@@ -168,7 +171,7 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
// The buffer was too small. Now that we got the required size, create another one big enough and retry.
buf := make([]byte, bufLen)
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
- data.size = uint32(unsafe.Sizeof(*data))
+ data.size = uint32(sizeAPI)
err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufLen, &bufLen)
if err == nil {