]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/NorFlashDxe : Fix the check of flash addresses
authorRonald Cron <ronald.cron@arm.com>
Fri, 23 Jan 2015 16:09:07 +0000 (16:09 +0000)
committeroliviermartin <oliviermartin@Edk2>
Fri, 23 Jan 2015 16:09:07 +0000 (16:09 +0000)
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

ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c

index 2f828ec86927210fecc5594370330d1ad4f8a473..3abbe5cb32bc2c7f44af3f014e6cb4515e022ff6 100644 (file)
@@ -805,8 +805,7 @@ NorFlashRead (
   OUT VOID                *Buffer\r
   )\r
 {\r
-  UINT32              NumBlocks;\r
-  UINTN               StartAddress;\r
+  UINTN  StartAddress;\r
 \r
   // The buffer must be valid\r
   if (Buffer == NULL) {\r
@@ -818,15 +817,7 @@ NorFlashRead (
     return EFI_SUCCESS;\r
   }\r
 \r
-  // All blocks must be within the device\r
-  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;\r
-\r
-  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {\r
-    DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed last block\n"));\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (Offset + BufferSizeInBytes >= Instance->Size) {\r
+  if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {\r
     DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));\r
     return EFI_INVALID_PARAMETER;\r
   }\r