Current code relies on last entry in hob to be MaxMemoryType enum value
which keeps changing on new memory type definition. If the HOB is
created by binaries built with older Edk2, current code leads to hang
which could be avoided by using hob size.

Signed-off-by: Baraneedharan Anbazhagan 
anbazha...@hp.com<mailto:anbazha...@hp.com>
---
MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index a5e32ebdba..014e4557bf 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -140,6 +140,7 @@ BmSetMemoryTypeInformationVariable (
   UINT32                       Current;
   UINT32                       Next;
   EFI_HOB_GUID_TYPE            *GuidHob;
+  UINTN                        NoOfEntries;
   BOOLEAN                      MemoryTypeInformationModified;
   BOOLEAN                      MemoryTypeInformationVariableExists;
   EFI_BOOT_MODE                BootMode;
@@ -200,6 +201,7 @@ BmSetMemoryTypeInformationVariable (
   }
   VariableSize                  = GET_GUID_HOB_DATA_SIZE (GuidHob);
+  NoOfEntries                   = VariableSize / 
sizeof(EFI_MEMORY_TYPE_INFORMATION);
   PreviousMemoryTypeInformation = AllocateCopyPool (VariableSize, 
GET_GUID_HOB_DATA (GuidHob));
   if (PreviousMemoryTypeInformation == NULL) {
     return;
@@ -212,8 +214,8 @@ BmSetMemoryTypeInformationVariable (
   DEBUG ((DEBUG_INFO, " Type    Pages     Pages     Pages  \n"));
   DEBUG ((DEBUG_INFO, "======  ========  ========  ========\n"));
-  for (Index = 0; PreviousMemoryTypeInformation[Index].Type != 
EfiMaxMemoryType; Index++) {
-    for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != 
EfiMaxMemoryType; Index1++) {
+  for (Index = 0; Index < NoOfEntries; Index++) {
+    for (Index1 = 0; Index1 < NoOfEntries; Index1++) {
       if (PreviousMemoryTypeInformation[Index].Type == 
CurrentMemoryTypeInformation[Index1].Type) {
         break;
       }
--
2.38.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97040): https://edk2.groups.io/g/devel/message/97040
Mute This Topic: https://groups.io/mt/95495909/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to