mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[FREELDR] PcMemGetBiosMemoryMap(): Add checks for entry sizes and bare handling of error case. CORE-13332
This commit is contained in:
parent
2ddebe3291
commit
1456310503
2 changed files with 28 additions and 0 deletions
|
@ -293,6 +293,29 @@ PcMemGetBiosMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG MaxMemoryMapSi
|
|||
goto nextRange;
|
||||
}
|
||||
|
||||
/* Extra safety: unexpected entry length.
|
||||
* All in-between values are valid too, as x86 is little-indian
|
||||
* and only lower byte is used per ACPI 6.2-A.
|
||||
*/
|
||||
if (Regs.x.ecx < RTL_SIZEOF_THROUGH_FIELD(BIOS_MEMORY_MAP, Type) ||
|
||||
Regs.x.ecx > sizeof(BIOS_MEMORY_MAP))
|
||||
{
|
||||
ERR("Int 15h AX=E820h returned an invalid entry length! (would-be-PcBiosMapCount = %lu, Entry length = (%Iu <=) %lu (<= %Iu))\n\n",
|
||||
PcBiosMapCount, RTL_SIZEOF_THROUGH_FIELD(BIOS_MEMORY_MAP, Type), Regs.x.ecx, sizeof(BIOS_MEMORY_MAP));
|
||||
/* Warn user, unless wrong case is "first and not too big entry", which is otherwise harmless. */
|
||||
if (PcBiosMapCount > 0 || Regs.x.ecx > sizeof(BIOS_MEMORY_MAP))
|
||||
{
|
||||
ASSERTMSG("Int 15h AX=E820h returned an invalid entry length!", FALSE);
|
||||
}
|
||||
/* We keep previous entries (if any), but do not dare trying next entries.
|
||||
* We assume these entries are good to use as is. If they are not, we are in trouble...
|
||||
* (And don't ask what happens if BIOS actually overflowed our entry buffer...)
|
||||
*
|
||||
* FIXME: Safer = revert previous entries, Safest = blacklist this BIOS.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy data to global buffer */
|
||||
RtlCopyMemory(&PcBiosMemoryMap[PcBiosMapCount], (PVOID)BIOSCALLBUFFER, Regs.x.ecx);
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ typedef struct
|
|||
ULONG Reserved;
|
||||
} BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP;
|
||||
|
||||
/* Int 15h AX=E820h Entry minimal size. */
|
||||
C_ASSERT(FIELD_OFFSET(BIOS_MEMORY_MAP, Reserved) == 20);
|
||||
/* Int 15h AX=E820h Entry maximal size. */
|
||||
C_ASSERT(sizeof(BIOS_MEMORY_MAP) == 24);
|
||||
|
||||
/* FIXME: Should be moved to NDK, and respective ACPI header files */
|
||||
typedef struct _ACPI_BIOS_DATA
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue