From a65c22c9c99bb4fb504a0ea0613e1968cbde65e3 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Sat, 30 Dec 2023 14:36:37 +0100 Subject: [PATCH] Make a copy of modules list, because RtlTokenizeWideString() modifies input data --- xtldr2/xtldr.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/xtldr2/xtldr.c b/xtldr2/xtldr.c index 09d786a..be50e7d 100644 --- a/xtldr2/xtldr.c +++ b/xtldr2/xtldr.c @@ -113,10 +113,10 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) PWCHAR ModulesList, ProtocolName; PLIST_ENTRY OptionsListEntry; PXTBL_CONFIG_ENTRY Option; + SIZE_T ModuleListLength; EFI_STATUS Status; /* Set default values */ - ModulesList = NULL; ProtocolName = NULL; /* Iterate through all options provided by boot menu entry */ @@ -134,8 +134,19 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) } else if(RtlCompareWideStringInsensitive(Option->Name, L"BOOTMODULES", 0) == 0) { - /* Set protocol name */ - ModulesList = Option->Value; + /* Check a length of modules list */ + ModuleListLength = RtlWideStringLength(Option->Value, 0); + + Status = BlMemoryAllocatePool(sizeof(PWCHAR) * ModuleListLength, (PVOID *)&ModulesList); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to allocate memory, print error message and return status code */ + BlDebugPrint(L"ERROR: Memory allocation failure (Status Code: 0x%lx)\n"); + return STATUS_EFI_OUT_OF_RESOURCES; + } + + /* Make a copy of modules list */ + RtlCopyMemory(ModulesList, Option->Value, sizeof(PWCHAR) * ModuleListLength); } /* Move to the next option entry */