diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-10-14 06:33:20 +0000 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-10-14 06:49:29 +0000 |
commit | aa20eecef92d7b9997609641fa37ab18a560c18d (patch) | |
tree | a9388171f52d99521b0b0b75d82eaca49d9d98cf | |
parent | api: adapter: handle cases explicitly in dev query callback (diff) | |
download | wireguard-nt-aa20eecef92d7b9997609641fa37ab18a560c18d.tar.xz wireguard-nt-aa20eecef92d7b9997609641fa37ab18a560c18d.zip |
api: use proper instance id bounds
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | api/adapter.c | 2 | ||||
-rw-r--r-- | api/adapter.h | 4 | ||||
-rw-r--r-- | api/driver.c | 4 | ||||
-rw-r--r-- | api/rundll32.c | 6 | ||||
-rw-r--r-- | api/rundll32.h | 2 | ||||
-rw-r--r-- | setupapihost/host_win7.h | 4 |
6 files changed, 11 insertions, 11 deletions
diff --git a/api/adapter.c b/api/adapter.c index 1e3219c..e109035 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -524,7 +524,7 @@ DeviceCreateCallback( SW_DEVICE_CREATE_CTX *Ctx = Context; Ctx->CreateResult = CreateResult; if (DeviceInstanceId) - wcsncpy_s(Ctx->DeviceInstanceId, MAX_INSTANCE_ID, DeviceInstanceId, _TRUNCATE); + wcsncpy_s(Ctx->DeviceInstanceId, MAX_DEVICE_ID_LEN, DeviceInstanceId, _TRUNCATE); SetEvent(Ctx->Triggered); } diff --git a/api/adapter.h b/api/adapter.h index 195f464..238522c 100644 --- a/api/adapter.h +++ b/api/adapter.h @@ -8,9 +8,9 @@ #include "wireguard.h" #include <IPExport.h> #include <SetupAPI.h> +#include <cfgmgr32.h> #include <Windows.h> -#define MAX_INSTANCE_ID MAX_PATH /* TODO: Is MAX_PATH always enough? */ #define WIREGUARD_HWID L"WireGuard" #define WIREGUARD_ENUMERATOR (IsWindows7 ? L"ROOT\\" WIREGUARD_HWID : L"SWD\\" WIREGUARD_HWID) @@ -28,7 +28,7 @@ typedef struct _WIREGUARD_ADAPTER SP_DEVINFO_DATA DevInfoData; WCHAR *InterfaceFilename; GUID CfgInstanceID; - WCHAR DevInstanceID[MAX_INSTANCE_ID]; + WCHAR DevInstanceID[MAX_DEVICE_ID_LEN]; DWORD LuidIndex; DWORD IfType; DWORD IfIndex; diff --git a/api/driver.c b/api/driver.c index 2671c93..66d87ee 100644 --- a/api/driver.c +++ b/api/driver.c @@ -70,7 +70,7 @@ SnapshotConfigurationAndState( 0); DWORD LastError = ERROR_SUCCESS; - WCHAR InstanceId[MAX_INSTANCE_ID]; + WCHAR InstanceId[MAX_DEVICE_ID_LEN]; DWORD RequiredBytes = _countof(InstanceId); if (!SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, InstanceId, RequiredBytes, &RequiredBytes)) { @@ -137,7 +137,7 @@ RestoreConfigurationAndState( 0); DWORD LastError = ERROR_SUCCESS; - WCHAR InstanceId[MAX_INSTANCE_ID]; + WCHAR InstanceId[MAX_DEVICE_ID_LEN]; DWORD RequiredBytes = _countof(InstanceId); if (!SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, InstanceId, RequiredBytes, &RequiredBytes)) { diff --git a/api/rundll32.c b/api/rundll32.c index cdc5412..bff936a 100644 --- a/api/rundll32.c +++ b/api/rundll32.c @@ -311,7 +311,7 @@ InvokeClassInstaller(_In_ LPCWSTR Action, _In_ LPCWSTR Function, _In_ HDEVINFO D { LOG(WIREGUARD_LOG_INFO, L"Spawning native process to %s instance", Action); - WCHAR InstanceId[MAX_INSTANCE_ID]; + WCHAR InstanceId[MAX_DEVICE_ID_LEN]; DWORD RequiredChars = _countof(InstanceId); if (!SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, InstanceId, RequiredChars, &RequiredChars)) { @@ -374,7 +374,7 @@ CreateInstanceWin7ViaRundll32(LPWSTR InstanceId) LOG(WIREGUARD_LOG_INFO, L"Spawning native process to create instance"); DWORD LastError; - WCHAR Response[MAX_INSTANCE_ID + 1]; + WCHAR Response[MAX_DEVICE_ID_LEN + 1]; if (!ExecuteRunDll32(L"CreateInstanceWin7", L"", Response, _countof(Response))) { LastError = LOG_LAST_ERROR(L"Error executing worker process"); @@ -389,7 +389,7 @@ CreateInstanceWin7ViaRundll32(LPWSTR InstanceId) } LastError = wcstoul(Argv[0], NULL, 16); if (LastError == ERROR_SUCCESS) - wcsncpy_s(InstanceId, MAX_INSTANCE_ID, Argv[1], _TRUNCATE); + wcsncpy_s(InstanceId, MAX_DEVICE_ID_LEN, Argv[1], _TRUNCATE); cleanupArgv: LocalFree(Argv); cleanup: diff --git a/api/rundll32.h b/api/rundll32.h index 030419c..762bfcf 100644 --- a/api/rundll32.h +++ b/api/rundll32.h @@ -23,4 +23,4 @@ DisableInstanceViaRundll32(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoD _Return_type_success_(return != FALSE) BOOL -CreateInstanceWin7ViaRundll32(_Out_writes_z_(MAX_INSTANCE_ID) LPWSTR InstanceId);
\ No newline at end of file +CreateInstanceWin7ViaRundll32(_Out_writes_z_(MAX_DEVICE_ID_LEN) LPWSTR InstanceId);
\ No newline at end of file diff --git a/setupapihost/host_win7.h b/setupapihost/host_win7.h index 4350533..1e6163d 100644 --- a/setupapihost/host_win7.h +++ b/setupapihost/host_win7.h @@ -4,8 +4,8 @@ */ #include <devguid.h> +#include <cfgmgr32.h> -#define MAX_INSTANCE_ID MAX_PATH /* TODO: Is MAX_PATH always enough? */ #define WIREGUARD_HWID L"WireGuard" VOID __stdcall CreateInstanceWin7(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) @@ -13,7 +13,7 @@ VOID __stdcall CreateInstanceWin7(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, #pragma EXPORT DWORD LastError = ERROR_SUCCESS; - WCHAR InstanceId[MAX_INSTANCE_ID] = { 0 }; + WCHAR InstanceId[MAX_DEVICE_ID_LEN] = { 0 }; HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL); if (DevInfo == INVALID_HANDLE_VALUE) |