From 44568f81cbc88690a11f87b3f7f9e67838547cd1 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 30 Oct 2020 07:09:13 +0100 Subject: [PATCH] api: make architecture-dependent wintun.dll selection an explicit select Suggested-by: Jason A. Donenfeld Signed-off-by: Simon Rozman --- api/adapter.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index 790ed53..1aa8a03 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1363,9 +1363,21 @@ ExecuteRunDll32( Result = ERROR_BUFFER_OVERFLOW; goto cleanupDirectory; } - if ((Result = ResourceCopyToFile( - DllPath, NativeMachine == IMAGE_FILE_MACHINE_ARM64 ? L"wintun-arm64.dll" : L"wintun-amd64.dll")) != - ERROR_SUCCESS) + const WCHAR *WintunDllResourceName; + switch (NativeMachine) + { + case IMAGE_FILE_MACHINE_AMD64: + WintunDllResourceName = L"wintun-amd64.dll"; + break; + case IMAGE_FILE_MACHINE_ARM64: + WintunDllResourceName = L"wintun-arm64.dll"; + break; + default: + LOG(WINTUN_LOG_ERR, L"Failed to copy resource"); + Result = ERROR_NOT_SUPPORTED; + goto cleanupDirectory; + } + if ((Result = ResourceCopyToFile(DllPath, WintunDllResourceName)) != ERROR_SUCCESS) { LOG(WINTUN_LOG_ERR, L"Failed to copy resource"); goto cleanupDelete;