Reallocate memory when updating existing config entry via BlSetConfigValue()

This commit is contained in:
Rafal Kupiec 2024-03-02 17:15:37 +01:00
parent 01983ef677
commit bd6516cdf9
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -88,6 +88,7 @@ BlSetConfigValue(IN CONST PWCHAR ConfigName,
{
PXTBL_CONFIG_ENTRY ConfigEntry;
PLIST_ENTRY ConfigListEntry;
EFI_STATUS Status;
SIZE_T Length;
/* Get config entry name length */
@ -103,8 +104,27 @@ BlSetConfigValue(IN CONST PWCHAR ConfigName,
/* Check if requested configuration found */
if(RtlCompareWideStringInsensitive(ConfigEntry->Name, ConfigName, Length) == 0)
{
/* Check new config value length */
Length = RtlWideStringLength(ConfigValue, 0);
/* Reallocate memory for new config value */
Status = BlFreeMemoryPool(ConfigEntry->Value);
if(Status == STATUS_EFI_SUCCESS)
{
/* Successfully freed memory, allocate a new pool */
Status = BlAllocateMemoryPool((Length + 1) * sizeof(WCHAR), (PVOID *)&ConfigEntry->Value);
}
/* Check memory reallocation status */
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to reallocate memory */
return Status;
}
/* Update config value */
ConfigEntry->Value = ConfigValue;
RtlCopyMemory(ConfigEntry->Value, ConfigValue, Length * sizeof(WCHAR));
ConfigEntry->Value[Length] = L'\0';
/* Return success */
return STATUS_EFI_SUCCESS;