From c7a26dfef35579bf24059748fae7a87cabfe166f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 19 Apr 2019 10:19:00 +0900 Subject: [PATCH] setupapi: actually fix padding by rounding up to sizeof(void*) --- tun/wintun/setupapi/setupapi_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tun/wintun/setupapi/setupapi_windows.go b/tun/wintun/setupapi/setupapi_windows.go index 1731f4b..8524558 100644 --- a/tun/wintun/setupapi/setupapi_windows.go +++ b/tun/wintun/setupapi/setupapi_windows.go @@ -157,7 +157,7 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0])) // 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) + sizeAPI := ((unsafe.Sizeof(uintptr(0)) - 1) | (unsafe.Offsetof(data.hardwareID) + unsafe.Sizeof(data.hardwareID) - 1) + 1) data.size = uint32(sizeAPI) err := setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufCapacity, &bufLen)