Skip to content

Commit

Permalink
Fwpm functions return HRESULT. Be consistent in success checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Jun 9, 2021
1 parent 7cd2e33 commit 6ff508d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packetWin7/npf/npf/Loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,19 +881,16 @@ Callouts and filters will be removed during DriverUnload.
&g_WFPEngineHandle
);

if (status != NO_ERROR || !g_WFPEngineHandle || g_WFPEngineHandle == INVALID_HANDLE_VALUE)
if (!NT_SUCCESS(status) || !g_WFPEngineHandle || g_WFPEngineHandle == INVALID_HANDLE_VALUE)
{
g_WFPEngineHandle = INVALID_HANDLE_VALUE;
goto Exit;
}
engineOpened = TRUE;

status = FwpmTransactionBegin(g_WFPEngineHandle, 0);
if (status != NO_ERROR)
if (!NT_SUCCESS(status))
{
// FwpmTransactionBegin annotations assume transaction is always started, even if there's a failure.
// We have to explicitly tell the engine that it isn't necessary to release/abort the transaction.
_Analysis_assume_lock_not_held_(g_WFPEngineHandle);
goto Exit;
}
inTransaction = TRUE;
Expand All @@ -907,7 +904,7 @@ Callouts and filters will be removed during DriverUnload.
provider.displayData.description = NPF_DRIVER_NAME_NORMAL_WIDECHAR;
provider.serviceName = NPF_DRIVER_NAME_SMALL_WIDECHAR;
status = FwpmProviderAdd(g_WFPEngineHandle, &provider, NULL);
if (status != NO_ERROR)
if (!NT_SUCCESS(status))
{
goto Exit;
}
Expand All @@ -925,7 +922,7 @@ Callouts and filters will be removed during DriverUnload.
// implementation.

status = FwpmSubLayerAdd(g_WFPEngineHandle, &NPFSubLayer, NULL);
if (status != NO_ERROR)
if (!NT_SUCCESS(status))
{
goto Exit;
}
Expand Down Expand Up @@ -994,12 +991,12 @@ Callouts and filters will be removed during DriverUnload.
if (!NT_SUCCESS(status))
{
IF_LOUD(DbgPrint("NPF_RegisterCallouts: failed to register callouts\n");)
if (inTransaction && g_WFPEngineHandle && g_WFPEngineHandle != INVALID_HANDLE_VALUE)
if (inTransaction)
{
FwpmTransactionAbort(g_WFPEngineHandle);
_Analysis_assume_lock_not_held_(g_WFPEngineHandle); // Potential leak if "FwpmTransactionAbort" fails
}
if (engineOpened && g_WFPEngineHandle && g_WFPEngineHandle != INVALID_HANDLE_VALUE)
if (engineOpened)
{
FwpmEngineClose(g_WFPEngineHandle);
g_WFPEngineHandle = INVALID_HANDLE_VALUE;
Expand Down

0 comments on commit 6ff508d

Please sign in to comment.