diff --git a/tools/network/dnssec/config_windows.go b/tools/network/dnssec/config_windows.go index 36c0aaf377..f41d6b6be7 100644 --- a/tools/network/dnssec/config_windows.go +++ b/tools/network/dnssec/config_windows.go @@ -21,7 +21,6 @@ package dnssec import ( "fmt" - "runtime/debug" "time" "unsafe" @@ -94,25 +93,31 @@ type fixedInfoWithOverlay struct { // See GetNetworkParams for details: // https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getnetworkparams func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error) { - // disable GC to prevent fi collection earlier than lookups in fi completed - pct := debug.SetGCPercent(-1) - defer debug.SetGCPercent(pct) + ulSize := uint32(unsafe.Sizeof(fixedInfoWithOverlay{})) + + buf, err := windows.LocalAlloc(windows.LMEM_FIXED | windows.LMEM_ZEROINIT, ulSize) + if err != nil { + err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize) + return + } + + defer windows.LocalFree(windows.Handle(buf)) - var fi fixedInfoWithOverlay - var ulSize uint32 = uint32(unsafe.Sizeof(fi)) ret, _, _ := networkParamsProc.Call( - uintptr(unsafe.Pointer(&fi)), + buf, uintptr(unsafe.Pointer(&ulSize)), ) if ret != 0 { if windows.Errno(ret) == windows.ERROR_BUFFER_OVERFLOW { - err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fi), ret) + err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fixedInfoWithOverlay{}), ret) return } err = fmt.Errorf("GetNetworkParams failed with code is %x", ret) return } + fi := (*fixedInfoWithOverlay)(unsafe.Pointer(buf)) + var p *ipAddrString = &fi.DnsServerList for { ip := make([]byte, ip_size)