From cb4bd3db8b3842215f66e04c2d274faa43b9f764 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Tue, 9 Jan 2024 16:24:57 +0100 Subject: [PATCH] Return a copy of config value, so that it won't get altered --- xtldr/config.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/xtldr/config.c b/xtldr/config.c index 763a03d..c2e8569 100644 --- a/xtldr/config.c +++ b/xtldr/config.c @@ -25,10 +25,12 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName) { PXTBL_CONFIG_ENTRY ConfigEntry; PLIST_ENTRY ConfigListEntry; - SIZE_T Length; + SIZE_T KeyLength, ValueLength; + EFI_STATUS Status; + PWCHAR Value; /* Get config entry name length */ - Length = RtlWideStringLength(ConfigName, 0); + KeyLength = RtlWideStringLength(ConfigName, 0); /* Iterate through config entries */ ConfigListEntry = BlpConfig.Flink; @@ -38,10 +40,24 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName) ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink); /* Check if requested configuration found */ - if(RtlCompareWideStringInsensitive(ConfigEntry->Name, ConfigName, Length) == 0) + if(RtlCompareWideStringInsensitive(ConfigEntry->Name, ConfigName, KeyLength) == 0) { - /* Return config value */ - return ConfigEntry->Value; + /* Get value length */ + ValueLength = RtlWideStringLength(ConfigEntry->Value, 0); + + /* Allocate memory for value */ + Status = BlMemoryAllocatePool(ValueLength * sizeof(WCHAR), (PVOID *)&Value); + if(Status != STATUS_EFI_SUCCESS) + { + /* Memory allocation failure, return NULL */ + BlDebugPrint(L"ERROR: Memory allocation failure (Status Code: 0x%lx)\n", Status); + return NULL; + } + + /* Copy value and return it */ + RtlCopyMemory(Value, ConfigEntry->Value, ValueLength * sizeof(WCHAR)); + Value[ValueLength] = 0; + return Value; } /* Move to the next config entry */