ArmPkg/NorFlashDxe : Fix the check of flash addresses
Fix the check to prevent any reading past the end of the nor flash. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron <ronald.cron@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16655 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2596e61a9b
commit
ac83357a43
@ -805,8 +805,7 @@ NorFlashRead (
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 NumBlocks;
|
UINTN StartAddress;
|
||||||
UINTN StartAddress;
|
|
||||||
|
|
||||||
// The buffer must be valid
|
// The buffer must be valid
|
||||||
if (Buffer == NULL) {
|
if (Buffer == NULL) {
|
||||||
@ -818,15 +817,7 @@ NorFlashRead (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All blocks must be within the device
|
if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {
|
||||||
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
|
|
||||||
|
|
||||||
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
|
|
||||||
DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed last block\n"));
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Offset + BufferSizeInBytes >= Instance->Size) {
|
|
||||||
DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));
|
DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user