From 361865684d12915a5b18bec9e3a0498763d60506 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 28 Apr 2025 13:40:24 +0200 Subject: [PATCH] MdeModulePkg: Correct CoreRemoveDebugImageInfoEntry() The UEFI specification does not allow NULL pointers in the EFI Debug Info Table. The TableSize field in the EFI Debug Info Table Header must always match the array size of the EFI Debug Info Table. Instead of creating a NULL entry when removing an entry, move the tail of the EFI Debug Info Table one slot to the front. Signed-off-by: Heinrich Schuchardt --- MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index eeb18f6e4725..53ca1202a110 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include "DxeMain.h" EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = { @@ -264,16 +265,23 @@ CoreRemoveDebugImageInfoEntry ( for (Index = 0; Index < mMaxTableEntries; Index++) { if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) { // - // Found a match. Free up the record, then NULL the pointer to indicate the slot - // is free. + // Found a match. Free up the table entry. + // Move the tail of the table one slot to the front. // CoreFreePool (Table[Index].NormalImage); - Table[Index].NormalImage = NULL; + CopyMem ( + &Table[Index], + &Table[Index + 1], + (mDebugInfoTableHeader.TableSize - Index - 1) * sizeof (void *) + ); // - // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status. + // Decrease the number of EFI_DEBUG_IMAGE_INFO elements + // Set the freed pointer to NULL. + // Set the the modified status in mDebugInfoTable. // mDebugInfoTableHeader.TableSize--; - mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED; + Table[mDebugInfoTableHeader.TableSize].NormalImage = NULL; + mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED; break; } }