ValidateFmpCapsule(), DisplayCapsuleImage(), ConvertBmpToGopBlt() will\r
receive untrusted input and do basic validation.\r
\r
- Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
#include <Protocol/FirmwareManagement.h>\r
#include <Protocol/DevicePath.h>\r
\r
-EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = NULL;\r
-BOOLEAN mIsVirtualAddrConverted = FALSE;\r
-BOOLEAN mDxeCapsuleLibEndOfDxe = FALSE;\r
+BOOLEAN mDxeCapsuleLibEndOfDxe = FALSE;\r
+EFI_EVENT mDxeCapsuleLibEndOfDxeEvent = NULL;\r
\r
/**\r
Initialize capsule related variables.\r
\r
}\r
\r
- ImageIndex = (UINTN) (Image - ImageHeader);\r
+ ImageIndex = (UINTN) Image - (UINTN) ImageHeader;\r
if ((ImageIndex % 4) != 0) {\r
//\r
// Bmp Image starts each row on a 32-bit boundary!\r
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
\r
ImagePayload = (DISPLAY_DISPLAY_PAYLOAD *)(CapsuleHeader + 1);\r
- PayloadSize = (UINTN)(CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER));\r
+ PayloadSize = CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER);\r
\r
if (ImagePayload->Version != 1) {\r
return EFI_UNSUPPORTED;\r
for (Index = 0; Index < FmpCapsuleHeader->EmbeddedDriverCount; Index++) {\r
DEBUG((DEBUG_VERBOSE, " ItemOffsetList[%d] - 0x%lx\n", Index, ItemOffsetList[Index]));\r
}\r
- for (; Index < (UINTN)(FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount); Index++) {\r
+ for (; Index < (UINT32)FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount; Index++) {\r
DEBUG((DEBUG_VERBOSE, " ItemOffsetList[%d] - 0x%lx\n", Index, ItemOffsetList[Index]));\r
ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);\r
\r
EFI_SYSTEM_RESOURCE_ENTRY Entry;\r
\r
EsrtGuidFound = FALSE;\r
-\r
- //\r
- // Check ESRT protocol\r
- //\r
- Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtProtocol);\r
- if (!EFI_ERROR(Status)) {\r
- Status = EsrtProtocol->GetEsrtEntry(&CapsuleHeader->CapsuleGuid, &Entry);\r
- if (!EFI_ERROR(Status)) {\r
- EsrtGuidFound = TRUE;\r
- }\r
- }\r
-\r
- //\r
- // Check ESRT configuration table\r
- //\r
- if (!EsrtGuidFound) {\r
- Status = EfiGetSystemConfigurationTable(&gEfiSystemResourceTableGuid, (VOID **)&Esrt);\r
- if (!EFI_ERROR(Status)) {\r
- ASSERT (Esrt != NULL);\r
- EsrtEntry = (VOID *)(Esrt + 1);\r
- for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {\r
+ if (mIsVirtualAddrConverted) {\r
+ if(mEsrtTable != NULL) {\r
+ EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1);\r
+ for (Index = 0; Index < mEsrtTable->FwResourceCount ; Index++, EsrtEntry++) {\r
if (CompareGuid(&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
EsrtGuidFound = TRUE;\r
break;\r
}\r
}\r
}\r
+ } else {\r
+ //\r
+ // Check ESRT protocol\r
+ //\r
+ Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtProtocol);\r
+ if (!EFI_ERROR(Status)) {\r
+ Status = EsrtProtocol->GetEsrtEntry(&CapsuleHeader->CapsuleGuid, &Entry);\r
+ if (!EFI_ERROR(Status)) {\r
+ EsrtGuidFound = TRUE;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Check ESRT configuration table\r
+ //\r
+ if (!EsrtGuidFound) {\r
+ Status = EfiGetSystemConfigurationTable(&gEfiSystemResourceTableGuid, (VOID **)&Esrt);\r
+ if (!EFI_ERROR(Status)) {\r
+ ASSERT (Esrt != NULL);\r
+ EsrtEntry = (VOID *)(Esrt + 1);\r
+ for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {\r
+ if (CompareGuid(&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
+ EsrtGuidFound = TRUE;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
}\r
if (!EsrtGuidFound) {\r
return FALSE;\r
IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- EFI_EVENT EndOfDxeEvent;\r
EFI_STATUS Status;\r
\r
Status = gBS->CreateEventEx (\r
DxeCapsuleLibEndOfDxe,\r
NULL,\r
&gEfiEndOfDxeEventGroupGuid,\r
- &EndOfDxeEvent\r
+ &mDxeCapsuleLibEndOfDxeEvent\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
\r
return EFI_SUCCESS;\r
}\r
+\r
+/**\r
+ The destructor function closes the End of DXE event.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The destructor completed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeCapsuleLibDestructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Close the End of DXE event.\r
+ //\r
+ Status = gBS->CloseEvent (mDxeCapsuleLibEndOfDxeEvent);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return EFI_SUCCESS;\r
+}\r