MdeModulePkg CapsuleApp: Check capsule header before using its Flags

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@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>
This commit is contained in:
Star Zeng 2018-07-13 15:50:16 +08:00
parent 95dd7a6ecd
commit d9c640b928
1 changed files with 38 additions and 0 deletions

View File

@ -715,6 +715,40 @@ CleanGatherList (
}
}
/**
Validate if it is valid capsule header
This function assumes the caller provided correct CapsuleHeader pointer
and CapsuleSize.
This function validates the fields in EFI_CAPSULE_HEADER.
@param[in] CapsuleHeader Points to a capsule header.
@param[in] CapsuleSize Size of the whole capsule image.
**/
BOOLEAN
IsValidCapsuleHeader (
IN EFI_CAPSULE_HEADER *CapsuleHeader,
IN UINT64 CapsuleSize
)
{
if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
return FALSE;
}
if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
return FALSE;
}
if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) {
return FALSE;
}
if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {
return FALSE;
}
return TRUE;
}
/**
Print APP usage.
**/
@ -891,6 +925,10 @@ UefiMain (
Print(L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName);
goto Done;
}
if (!IsValidCapsuleHeader (CapsuleBuffer[Index], FileSize[Index])) {
Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
return EFI_INVALID_PARAMETER;
}
}
//