X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FApplication%2FCapsuleApp%2FCapsuleDump.c;h=45c3ecd050ab18a6b5702680ee9fdff7b39706dd;hb=fb57c30b703ee64415c43102862cfc2c2f2664be;hp=6c1320942bf423929e5cc6c67c9f66d12e5e8639;hpb=2e3032b4aae427fded0d7b4e5fefcd13f6576bbc;p=mirror_edk2.git diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c index 6c1320942b..45c3ecd050 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -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. @@ -214,7 +232,7 @@ IsNestedFmpCapsule ( // FMP GUID after ESRT one // NestedCapsuleHeader = (EFI_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize); - NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->HeaderSize - (UINTN)NestedCapsuleHeader; + NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->CapsuleImageSize- (UINTN)NestedCapsuleHeader; if (NestedCapsuleSize < sizeof(EFI_CAPSULE_HEADER)) { return FALSE; } @@ -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)) { @@ -283,7 +306,7 @@ Done: @retval EFI_UNSUPPORTED Input parameter is not valid. **/ EFI_STATUS -DmpCapsuleStatusVariable ( +DumpCapsuleStatusVariable ( VOID ) { @@ -454,9 +477,6 @@ DumpEsrtEntry ( Print(L" FwVersion - 0x%x\n", EsrtEntry->FwVersion); Print(L" LowestSupportedFwVersion - 0x%x\n", EsrtEntry->LowestSupportedFwVersion); Print(L" CapsuleFlags - 0x%x\n", EsrtEntry->CapsuleFlags); - Print(L" PERSIST_ACROSS_RESET - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET); - Print(L" POPULATE_SYSTEM_TABLE - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE); - Print(L" INITIATE_RESET - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_INITIATE_RESET); Print(L" LastAttemptVersion - 0x%x\n", EsrtEntry->LastAttemptVersion); Print(L" LastAttemptStatus - 0x%x (%a)\n", EsrtEntry->LastAttemptStatus, LastAttemptStatusToString(EsrtEntry->LastAttemptStatus)); } @@ -953,5 +973,7 @@ DumpFmpImage ( Status = WriteFileFromBuffer(ImageName, ImageSize, Image); Print(L"CapsuleApp: Dump %g ImageIndex (0x%x) to %s %r\n", ImageTypeId, ImageIndex, ImageName, Status); + FreePool (Image); + return ; }