Skip to content

Commit

Permalink
MdeModulePkg DxeCapsuleLibFmp: Refine the code to check FmpImageSize
Browse files Browse the repository at this point in the history
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 <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>
  • Loading branch information
lzeng14 committed Jul 27, 2018
1 parent 1010873 commit 83e1007
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ ValidateFmpCapsule (
}
FmpImageSize = (UINTN)EndOfPayload - ItemOffsetList[Index];

if (FmpImageSize < OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance)) {
DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER\n", FmpImageSize));
return EFI_INVALID_PARAMETER;
}
FmpImageHeaderSize = sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER);
if ((ImageHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) ||
(ImageHeader->Version < 1)) {
Expand All @@ -281,6 +277,10 @@ ValidateFmpCapsule (
if (ImageHeader->Version < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {
FmpImageHeaderSize = OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance);
}
if (FmpImageSize < FmpImageHeaderSize) {
DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) < FmpImageHeaderSize(0x%x)\n", FmpImageSize, FmpImageHeaderSize));
return EFI_INVALID_PARAMETER;
}

// No overflow
if (FmpImageSize != (UINT64)FmpImageHeaderSize + (UINT64)ImageHeader->UpdateImageSize + (UINT64)ImageHeader->UpdateVendorCodeSize) {
Expand Down

0 comments on commit 83e1007

Please sign in to comment.