https://git.reactos.org/?p=reactos.git;a=commitdiff;h=188f5dc50aa14e89360e3…
commit 188f5dc50aa14e89360e3ac5c962417efd53f9b1
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Mon Jun 14 05:05:07 2021 +0300
Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org>
CommitDate: Tue Dec 28 02:51:52 2021 +0300
[KMTESTS:IO] Avoid crashing in IoCreateFile test when pool allocations are failed
---
.../rostests/kmtests/ntos_io/IoCreateFile_drv.c | 52 ++++++++++++++--------
1 file changed, 34 insertions(+), 18 deletions(-)
diff --git a/modules/rostests/kmtests/ntos_io/IoCreateFile_drv.c
b/modules/rostests/kmtests/ntos_io/IoCreateFile_drv.c
index 33c295a53f4..241dd7b2a99 100644
--- a/modules/rostests/kmtests/ntos_io/IoCreateFile_drv.c
+++ b/modules/rostests/kmtests/ntos_io/IoCreateFile_drv.c
@@ -94,10 +94,15 @@ TestIrpHandler(
{
PREPARSE_DATA_BUFFER Reparse;
- Irp->Tail.Overlay.AuxiliaryBuffer = ExAllocatePoolWithTag(NonPagedPool,
MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
+ Irp->Tail.Overlay.AuxiliaryBuffer = ExAllocatePoolZero(NonPagedPool,
MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
Reparse = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
- RtlZeroMemory(Reparse, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
+ if (!Reparse)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto Finish;
+ }
+
Reparse->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
Reparse->ReparseDataLength = 12 + sizeof(L"\\??\\C:\\Documents and
Settings");
Reparse->MountPointReparseBuffer.SubstituteNameLength =
sizeof(L"\\??\\C:\\Documents and Settings") - sizeof(UNICODE_NULL);
@@ -109,31 +114,41 @@ TestIrpHandler(
else if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR)
&&
IoStack->FileObject->FileName.Buffer[1] == 'S')
{
+ PREPARSE_DATA_BUFFER Reparse;
+
if (IoStack->Flags & SL_STOP_ON_SYMLINK)
{
Status = STATUS_STOPPED_ON_SYMLINK;
+ goto Finish;
}
- else
+
+ Irp->Tail.Overlay.AuxiliaryBuffer = ExAllocatePoolZero(NonPagedPool,
MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
+ Reparse = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
+
+ if (!Reparse)
{
- PREPARSE_DATA_BUFFER Reparse;
-
- Irp->Tail.Overlay.AuxiliaryBuffer =
ExAllocatePoolWithTag(NonPagedPool, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
- Reparse = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
-
- RtlZeroMemory(Reparse, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
- Reparse->ReparseTag = IO_REPARSE_TAG_SYMLINK;
- Reparse->ReparseDataLength = 12 + sizeof(L"\\??\\C:\\Documents
and Settings");
- Reparse->SymbolicLinkReparseBuffer.SubstituteNameLength =
sizeof(L"\\??\\C:\\Documents and Settings") - sizeof(UNICODE_NULL);
- Reparse->SymbolicLinkReparseBuffer.PrintNameOffset =
sizeof(L"\\??\\C:\\Documents and Settings");
- RtlCopyMemory(Reparse->SymbolicLinkReparseBuffer.PathBuffer,
L"\\??\\C:\\Documents and Settings", sizeof(L"\\??\\C:\\Documents and
Settings"));
- Irp->IoStatus.Information = IO_REPARSE_TAG_SYMLINK;
- Status = STATUS_REPARSE;
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto Finish;
}
+
+ Reparse->ReparseTag = IO_REPARSE_TAG_SYMLINK;
+ Reparse->ReparseDataLength = 12 + sizeof(L"\\??\\C:\\Documents and
Settings");
+ Reparse->SymbolicLinkReparseBuffer.SubstituteNameLength =
sizeof(L"\\??\\C:\\Documents and Settings") - sizeof(UNICODE_NULL);
+ Reparse->SymbolicLinkReparseBuffer.PrintNameOffset =
sizeof(L"\\??\\C:\\Documents and Settings");
+ RtlCopyMemory(Reparse->SymbolicLinkReparseBuffer.PathBuffer,
L"\\??\\C:\\Documents and Settings", sizeof(L"\\??\\C:\\Documents and
Settings"));
+ Irp->IoStatus.Information = IO_REPARSE_TAG_SYMLINK;
+ Status = STATUS_REPARSE;
}
else
{
- Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(*Fcb), 'FwrI');
- RtlZeroMemory(Fcb, sizeof(*Fcb));
+ Fcb = ExAllocatePoolZero(NonPagedPool, sizeof(*Fcb), 'FwrI');
+
+ if (!Fcb)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto Finish;
+ }
+
ExInitializeFastMutex(&Fcb->HeaderMutex);
FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
Fcb->Header.AllocationSize.QuadPart = 0;
@@ -157,6 +172,7 @@ TestIrpHandler(
Status = STATUS_SUCCESS;
}
+Finish:
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);