mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 06:43:01 +00:00
[FREELDR] hwdisk: Add sanity checks to avoid infinite loop (#1731)
CORE-16204 CORE-16205
This commit is contained in:
parent
5dbc677cdd
commit
31aca248a1
1 changed files with 13 additions and 0 deletions
|
@ -82,6 +82,13 @@ DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
|
||||||
PARTITION_TABLE_ENTRY PartitionTableEntry;
|
PARTITION_TABLE_ENTRY PartitionTableEntry;
|
||||||
CHAR FileName[1];
|
CHAR FileName[1];
|
||||||
|
|
||||||
|
if (DiskReadBufferSize == 0)
|
||||||
|
{
|
||||||
|
ERR("DiskOpen(): DiskReadBufferSize is 0, something is wrong.\n");
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (!DissectArcPath(Path, FileName, &DriveNumber, &DrivePartition))
|
if (!DissectArcPath(Path, FileName, &DriveNumber, &DrivePartition))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -139,10 +146,16 @@ DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
||||||
BOOLEAN ret;
|
BOOLEAN ret;
|
||||||
ULONGLONG SectorOffset;
|
ULONGLONG SectorOffset;
|
||||||
|
|
||||||
|
ASSERT(DiskReadBufferSize > 0);
|
||||||
|
|
||||||
TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
|
TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
|
||||||
MaxSectors = DiskReadBufferSize / Context->SectorSize;
|
MaxSectors = DiskReadBufferSize / Context->SectorSize;
|
||||||
SectorOffset = Context->SectorNumber + Context->SectorOffset;
|
SectorOffset = Context->SectorNumber + Context->SectorOffset;
|
||||||
|
|
||||||
|
// If MaxSectors is 0, this will lead to infinite loop
|
||||||
|
// In release builds assertions are disabled, however we also have sanity checks in DiskOpen()
|
||||||
|
ASSERT(MaxSectors > 0);
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
||||||
while (TotalSectors)
|
while (TotalSectors)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue