aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-05-04 12:19:30 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-05-04 12:20:43 +0200
commite51b49604b5d00a641b698e7c40d4d46a06644c9 (patch)
tree19d8f65d2d7bc13333a739e4eb801c1af3b88dae /api
parentproject: fix typo in .editorconfig (diff)
downloadwintun-e51b49604b5d00a641b698e7c40d4d46a06644c9.tar.xz
wintun-e51b49604b5d00a641b698e7c40d4d46a06644c9.zip
api: don't return ERROR_SUCCESS if adapter doesn't come up
Otherwise we fail to remove the zombie adapter, and then the problem repeats itself. Note that this is part of a larger issue of clearing out bad GUIDs in NetSetup2 on recent Windows builds Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api')
-rw-r--r--api/adapter.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 47809f4..0043ae3 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -224,6 +224,13 @@ static _Return_type_success_(return != NULL) WCHAR *GetDeviceObjectFileName(_In_
SetLastError(LastError);
return NULL;
}
+ if (!Interfaces[0])
+ {
+ LOG(WINTUN_LOG_ERR, L"Received empty adapter object file name");
+ Free(Interfaces);
+ SetLastError(ERROR_DEVICE_NOT_AVAILABLE);
+ return NULL;
+ }
return Interfaces;
}
@@ -1652,13 +1659,24 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
goto cleanupTcpipAdapterRegKey;
}
- DEVPROPTYPE PropertyType;
for (int Tries = 0; Tries < 1000; ++Tries)
{
+ DEVPROPTYPE PropertyType;
+ INT32 ProblemCode;
NTSTATUS ProblemStatus;
if (SetupDiGetDevicePropertyW(
DevInfo,
&DevInfoData,
+ &DEVPKEY_Device_ProblemCode,
+ &PropertyType,
+ (PBYTE)&ProblemCode,
+ sizeof(ProblemCode),
+ NULL,
+ 0) &&
+ PropertyType == DEVPROP_TYPE_INT32 && ProblemCode &&
+ SetupDiGetDevicePropertyW(
+ DevInfo,
+ &DevInfoData,
&DEVPKEY_Device_ProblemStatus,
&PropertyType,
(PBYTE)&ProblemStatus,
@@ -1667,11 +1685,12 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
0) &&
PropertyType == DEVPROP_TYPE_NTSTATUS)
{
- LastError = RtlNtStatusToDosError(ProblemStatus);
- _Analysis_assume_(LastError != ERROR_SUCCESS);
if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999)
{
- LOG_ERROR(LastError, L"Failed to setup adapter (status: 0x%x)", ProblemStatus);
+ LastError = RtlNtStatusToDosError(ProblemStatus);
+ LOG_ERROR(LastError, L"Failed to setup adapter (code: 0x%x, status: 0x%x)", ProblemCode, ProblemStatus);
+ if (LastError == ERROR_SUCCESS)
+ LastError = ERROR_NOT_READY;
goto cleanupTcpipAdapterRegKey;
}
Sleep(10);