MdeModulePkg CapsuleApp: Check capsule header for -D and -N options

Then meaningful error message can be shown when the input image is
unexpected.

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-26 16:59:43 +08:00
parent 8b03c82d36
commit fb57c30b70
2 changed files with 90 additions and 34 deletions

View File

@@ -61,6 +61,24 @@ WriteFileFromBuffer (
IN VOID *Buffer
);
/**
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
);
/**
Dump UX capsule information.
@@ -248,6 +266,11 @@ DumpCapsule (
Print(L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName);
goto Done;
}
if (!IsValidCapsuleHeader (Buffer, FileSize)) {
Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
Status = EFI_INVALID_PARAMETER;
goto Done;
}
CapsuleHeader = Buffer;
if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {