[NTOS:MM] MmCanFileBeTruncated: Check whether second (optional) parameter was passed (#5248)

Second parameter is optional, so mark it as such and check whether it was passed. Fixes a sporadic 0x24 bugcheck caused by access violation when running ReactOS on NTFS volume with WinXP ntfs.sys.
This commit is contained in:
Adam Słaboń 2023-04-19 23:12:11 +02:00 committed by GitHub
parent 058726a2c1
commit 6eb8fe4f82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4209,9 +4209,11 @@ MmMapViewOfSection(IN PVOID SectionObject,
/* /*
* @unimplemented * @unimplemented
*/ */
BOOLEAN NTAPI BOOLEAN
MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, NTAPI
IN PLARGE_INTEGER NewFileSize) MmCanFileBeTruncated(
_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer,
_In_opt_ PLARGE_INTEGER NewFileSize)
{ {
BOOLEAN Ret; BOOLEAN Ret;
PMM_SECTION_SEGMENT Segment; PMM_SECTION_SEGMENT Segment;
@ -4237,7 +4239,7 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
/* If the cache is the only one holding a reference to the segment, then it's fine to resize */ /* If the cache is the only one holding a reference to the segment, then it's fine to resize */
Ret = TRUE; Ret = TRUE;
} }
else else if (NewFileSize != NULL)
{ {
/* We can't shrink, but we can extend */ /* We can't shrink, but we can extend */
Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart; Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
@ -4248,6 +4250,12 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
} }
#endif #endif
} }
else
{
DPRINT1("ERROR: File can't be truncated because it has references held to its data section\n");
Ret = FALSE;
}
MmUnlockSectionSegment(Segment); MmUnlockSectionSegment(Segment);
MmDereferenceSegment(Segment); MmDereferenceSegment(Segment);