MdeModulePkg DxeCapsuleLibFmp: Refine the code to check FmpImageSize
authorStar Zeng <star.zeng@intel.com>
Thu, 26 Jul 2018 05:57:11 +0000 (13:57 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 27 Jul 2018 08:04:12 +0000 (16:04 +0800)
The code to check FmpImageSize again OFFSET_OF
(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance)
can be refined to check against FmpImageHeaderSize.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c

index a1347b5..ee3adce 100644 (file)
@@ -268,10 +268,6 @@ ValidateFmpCapsule (
     }\r
     FmpImageSize = (UINTN)EndOfPayload - ItemOffsetList[Index];\r
 \r
-    if (FmpImageSize < OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance)) {\r
-      DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER\n", FmpImageSize));\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
     FmpImageHeaderSize = sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER);\r
     if ((ImageHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) ||\r
         (ImageHeader->Version < 1)) {\r
@@ -281,6 +277,10 @@ ValidateFmpCapsule (
     if (ImageHeader->Version < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {\r
       FmpImageHeaderSize = OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance);\r
     }\r
+    if (FmpImageSize < FmpImageHeaderSize) {\r
+      DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) < FmpImageHeaderSize(0x%x)\n", FmpImageSize, FmpImageHeaderSize));\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
 \r
     // No overflow\r
     if (FmpImageSize != (UINT64)FmpImageHeaderSize + (UINT64)ImageHeader->UpdateImageSize + (UINT64)ImageHeader->UpdateVendorCodeSize) {\r