Skip to content

Commit

Permalink
Replace regfltr sample calls to ExAllocatePoolWithTag with ExAllocate…
Browse files Browse the repository at this point in the history
…PoolZero. (#501)
  • Loading branch information
cpkleynhans committed Oct 15, 2021
1 parent 7895dd2 commit f5fb15f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
16 changes: 7 additions & 9 deletions general/registry/regfltr/sys/capture.c
Expand Up @@ -443,9 +443,9 @@ Return Value:
return Status;
}

TempBuffer = (PCALLBACK_CONTEXT) ExAllocatePoolWithTag(
PagedPool,
Length,
TempBuffer = (PCALLBACK_CONTEXT) ExAllocatePoolZero(
PagedPool,
Length,
PoolTag);

//
Expand Down Expand Up @@ -550,16 +550,14 @@ Return Value:

DestString->Length = SourceString->Length;
DestString->MaximumLength = SourceString->Length + sizeof(WCHAR);
DestString->Buffer = (PWSTR) ExAllocatePoolWithTag(
PagedPool,
DestString->MaximumLength,

DestString->Buffer = (PWSTR) ExAllocatePoolZero(
PagedPool,
DestString->MaximumLength,
PoolTag);

if (DestString->Buffer != NULL) {

RtlZeroMemory(DestString->Buffer, DestString->MaximumLength);

//
// It's a good practice to keep the contents of a try-except block to
// the bare minimum. By keeping the pool allocation call outside of the
Expand Down
6 changes: 6 additions & 0 deletions general/registry/regfltr/sys/driver.c
Expand Up @@ -162,6 +162,12 @@ Return value:
DPFLTR_ERROR_LEVEL,
"RegFltr: Use ed nt!Kd_IHVDRIVER_Mask 8 to enable more detailed printouts\n");

//
// Default to NonPagedPoolNx for non paged pool allocations where supported.
//

ExInitializeDriverRuntime(DrvRtPoolNxOptIn);

//
// Create our device object.
//
Expand Down
4 changes: 4 additions & 0 deletions general/registry/regfltr/sys/regfltr.vcxproj
Expand Up @@ -177,24 +177,28 @@
<ClCompile>
<ExceptionHandling>
</ExceptionHandling>
<PreprocessorDefinitions>POOL_NX_OPTIN;POOL_ZERO_DOWN_LEVEL_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<ExceptionHandling>
</ExceptionHandling>
<PreprocessorDefinitions>POOL_NX_OPTIN;POOL_ZERO_DOWN_LEVEL_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<ExceptionHandling>
</ExceptionHandling>
<PreprocessorDefinitions>POOL_NX_OPTIN;POOL_ZERO_DOWN_LEVEL_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<ExceptionHandling>
</ExceptionHandling>
<PreprocessorDefinitions>POOL_NX_OPTIN;POOL_ZERO_DOWN_LEVEL_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
9 changes: 4 additions & 5 deletions general/registry/regfltr/sys/txr.c
Expand Up @@ -61,21 +61,20 @@ Return Value:
//
// Create the registry callback context and the transaction callback context.
//

CallbackCtx = CreateCallbackContext(CALLBACK_MODE_TRANSACTION_ENLIST,
CALLBACK_ALTITUDE);
if (CallbackCtx == NULL) {
goto Exit;
}

RMCallbackCtx = (PRMCALLBACK_CONTEXT) ExAllocatePoolWithTag (
PagedPool,
sizeof(RMCALLBACK_CONTEXT),
RMCallbackCtx = (PRMCALLBACK_CONTEXT) ExAllocatePoolZero (
PagedPool,
sizeof(RMCALLBACK_CONTEXT),
REGFLTR_CONTEXT_POOL_TAG);
if (RMCallbackCtx == NULL) {
goto Exit;
}
RtlZeroMemory(RMCallbackCtx, sizeof(RMCALLBACK_CONTEXT));
CallbackCtx->RMCallbackCtx = RMCallbackCtx;

//
Expand Down
12 changes: 5 additions & 7 deletions general/registry/regfltr/sys/util.c
Expand Up @@ -91,18 +91,16 @@ Return Value:
PCALLBACK_CONTEXT CallbackCtx = NULL;
NTSTATUS Status;
BOOLEAN Success = FALSE;
CallbackCtx = (PCALLBACK_CONTEXT) ExAllocatePoolWithTag (
PagedPool,
sizeof(CALLBACK_CONTEXT),

CallbackCtx = (PCALLBACK_CONTEXT) ExAllocatePoolZero (
PagedPool,
sizeof(CALLBACK_CONTEXT),
REGFLTR_CONTEXT_POOL_TAG);

if (CallbackCtx == NULL) {
if (CallbackCtx == NULL) {
ErrorPrint("CreateCallbackContext failed due to insufficient resources.");
goto Exit;
}

RtlZeroMemory(CallbackCtx, sizeof(CALLBACK_CONTEXT));

CallbackCtx->CallbackMode = CallbackMode;
CallbackCtx->ProcessId = PsGetCurrentProcessId();
Expand Down

0 comments on commit f5fb15f

Please sign in to comment.