From 9f739df5956b3149400406817393b1be4348647d Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Tue, 23 Jan 2024 20:53:26 +0100 Subject: [PATCH] There is no need to allocate so much memory --- xtldr/config.c | 10 +++++----- xtldr/xtldr.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xtldr/config.c b/xtldr/config.c index 7af8603..b0a8249 100644 --- a/xtldr/config.c +++ b/xtldr/config.c @@ -269,11 +269,11 @@ BlpParseCommandLine(VOID) if(Status == STATUS_EFI_SUCCESS) { /* Allocate more memory for option name */ - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (KeyLength + 1), (PVOID*)&Option->Name); if(Status == STATUS_EFI_SUCCESS) { /* Allocate even more memory for option value */ - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (ValueLength + 1), (PVOID*)&Option->Value); } } if(Status != STATUS_EFI_SUCCESS) @@ -390,7 +390,7 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig, if(Status == STATUS_EFI_SUCCESS) { /* Allocate more memory for section name */ - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (SectionLength + 1), (PVOID*)&Section->SectionName); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (SectionLength + 1), (PVOID*)&Section->SectionName); } if(Status != STATUS_EFI_SUCCESS) { @@ -460,11 +460,11 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig, if(Status == STATUS_EFI_SUCCESS) { /* Allocate more memory for option name */ - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (KeyLength + 1), (PVOID*)&Option->Name); if(Status == STATUS_EFI_SUCCESS) { /* Allocate even more memory for option value */ - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (ValueLength + 1), (PVOID*)&Option->Value); } } if(Status != STATUS_EFI_SUCCESS) diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index b77f8a0..87a99f8 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -200,7 +200,7 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) /* Check a length of modules list */ ModuleListLength = RtlWideStringLength(Option->Value, 0); - Status = BlAllocateMemoryPool(sizeof(PWCHAR) * ModuleListLength, (PVOID *)&ModulesList); + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (ModuleListLength + 1), (PVOID *)&ModulesList); if(Status != STATUS_EFI_SUCCESS) { /* Failed to allocate memory, print error message and return status code */ @@ -209,7 +209,7 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) } /* Make a copy of modules list */ - RtlCopyMemory(ModulesList, Option->Value, sizeof(PWCHAR) * ModuleListLength); + RtlCopyMemory(ModulesList, Option->Value, sizeof(WCHAR) * (ModuleListLength + 1)); } else if(RtlCompareWideStringInsensitive(Option->Name, L"SYSTEMTYPE", 0) == 0) { @@ -219,7 +219,7 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) else if(RtlCompareWideStringInsensitive(Option->Name, L"SYSTEMPATH", 0) == 0) { /* System path found, get volume device path */ - Status = BlGetVolumeDevicePath((PWCHAR)Option->Value, &BootParameters.DevicePath, + Status = BlGetVolumeDevicePath(Option->Value, &BootParameters.DevicePath, &BootParameters.ArcName, &BootParameters.SystemPath); if(Status != STATUS_EFI_SUCCESS) {