diff options
author | 2021-10-07 22:42:52 +0000 | |
---|---|---|
committer | 2021-10-11 16:12:09 +0000 | |
commit | 6f51e33644a7741d2c8ccc8e5d82bc2a60689f10 (patch) | |
tree | 26c67ef23fe453d314e8190811d1e15758818f8f | |
parent | api: adapter: open devinst after arrival and skip stub on win8 (diff) | |
download | wireguard-nt-6f51e33644a7741d2c8ccc8e5d82bc2a60689f10.tar.xz wireguard-nt-6f51e33644a7741d2c8ccc8e5d82bc2a60689f10.zip |
api: adapter: ensure file handle opens on win7
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | api/adapter_win7.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/api/adapter_win7.h b/api/adapter_win7.h index 51d6902..400af2c 100644 --- a/api/adapter_win7.h +++ b/api/adapter_win7.h @@ -23,22 +23,28 @@ WaitForInterfaceWin7(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData, _ DWORD ValType, Zero; WCHAR *FileName = NULL; HKEY Key = INVALID_HANDLE_VALUE; + HANDLE FileHandle = INVALID_HANDLE_VALUE; BOOLEAN Ret = FALSE; for (int i = 0; i < 1500; ++i) { if (i) Sleep(10); if (Key == INVALID_HANDLE_VALUE) - { Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); - if (Key == INVALID_HANDLE_VALUE) - continue; - } - _Analysis_assume_(Key); if (!FileName) FileName = AdapterGetDeviceObjectFileName(DevInstanceId); + if (FileName && FileHandle == INVALID_HANDLE_VALUE) + FileHandle = CreateFileW( + FileName, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + 0, + NULL); Zero = 0; - if (FileName && RegQueryValueExW(Key, L"NetCfgInstanceId", NULL, &ValType, NULL, &Zero) != ERROR_MORE_DATA && + if (FileName && FileHandle != INVALID_HANDLE_VALUE && Key != INVALID_HANDLE_VALUE && Key && + RegQueryValueExW(Key, L"NetCfgInstanceId", NULL, &ValType, NULL, &Zero) != ERROR_MORE_DATA && CM_Get_DevNode_Status(&Status, &Number, DevInfoData->DevInst, 0) == CR_SUCCESS && !(Status & DN_HAS_PROBLEM) && !Number) { @@ -46,8 +52,10 @@ WaitForInterfaceWin7(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData, _ break; } } - if (Key != INVALID_HANDLE_VALUE) + if (Key != INVALID_HANDLE_VALUE && Key) RegCloseKey(Key); + if (FileHandle != INVALID_HANDLE_VALUE) + CloseHandle(FileHandle); Free(FileName); return Ret; } |