]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg: do not ASSERT() on valid external input
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 5 May 2015 15:51:44 +0000 (15:51 +0000)
committeroliviermartin <oliviermartin@Edk2>
Tue, 5 May 2015 15:51:44 +0000 (15:51 +0000)
Since ASSERT()s are enabled even on all ArmPlatformPkg RELEASE
builds, ASSERT()ing on a valid FDT header will crash the firmware
if the user selects an incorrect file. Since ASSERT() is meant to
catch internal inconsistencies in the firmware, its use here is
inappropriate.

Instead, handle it as a normal error condition.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17309 6f19259b-4bc3-4df7-8a09-765794883524

EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c

index b6f5c3e58d3ae1e20b2e5d0d2e932419f4bc01ba..fb2ae6071a0dcd5de83a34ce467296789866be34 100644 (file)
@@ -94,15 +94,16 @@ InstallFdt (
     goto Error;\r
   }\r
 \r
-  // Check the FDT header is valid. We only make this check in DEBUG mode in\r
-  // case the FDT header change on production device and this ASSERT() becomes\r
-  // not valid.\r
-  ASSERT (fdt_check_header ((VOID*)(UINTN)FdtBlobBase) == 0);\r
-\r
   //\r
-  // Ensure the Size of the Device Tree is smaller than the size of the read file\r
+  // Ensure that the FDT header is valid and that the Size of the Device Tree\r
+  // is smaller than the size of the read file\r
   //\r
-  ASSERT ((UINTN)fdt_totalsize ((VOID*)(UINTN)FdtBlobBase) <= FdtBlobSize);\r
+  if (fdt_check_header ((VOID*)(UINTN)FdtBlobBase) != 0 ||\r
+      (UINTN)fdt_totalsize ((VOID*)(UINTN)FdtBlobBase) > FdtBlobSize) {\r
+    DEBUG ((EFI_D_ERROR, "InstallFdt() - loaded FDT binary image seems corrupt\n"));\r
+    Status = EFI_LOAD_ERROR;\r
+    goto Error;\r
+  }\r
 \r
   //\r
   // Store the FDT as Runtime Service Data to prevent the Kernel from\r