AllocateCopyPool(AllocationSize, *Buffer) will copy "AllocationSize" bytes of
memory from old "Buffer" to new allocated one. If "AllocationSize" is bigger
than size of "Buffer", heap memory overflow occurs during copy.
One solution is to allocate pool first then copy the necessary bytes to new
memory. Another is using ReallocatePool instead if old buffer will be freed
on spot.
Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Bi Dandan <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
//\r
// now do the replacements...\r
//\r
//\r
// now do the replacements...\r
//\r
- NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);\r
+ NewCommandLine1 = AllocateZeroPool (NewSize);\r
NewCommandLine2 = AllocateZeroPool(NewSize);\r
ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r
if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r
NewCommandLine2 = AllocateZeroPool(NewSize);\r
ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r
if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r
SHELL_FREE_NON_NULL(ItemTemp);\r
return (NULL);\r
}\r
SHELL_FREE_NON_NULL(ItemTemp);\r
return (NULL);\r
}\r
+ CopyMem (NewCommandLine1, OriginalCommandLine, StrSize (OriginalCommandLine));\r
+\r
for (MasterEnvList = EfiShellGetEnv(NULL)\r
; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
; MasterEnvList += StrLen(MasterEnvList) + 1\r
for (MasterEnvList = EfiShellGetEnv(NULL)\r
; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
; MasterEnvList += StrLen(MasterEnvList) + 1\r
OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32)));\r
OriginalOptionDataSize -= OriginalSize;\r
NewSize = OriginalSize - OriginalOptionDataSize + DataSize;\r
OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32)));\r
OriginalOptionDataSize -= OriginalSize;\r
NewSize = OriginalSize - OriginalOptionDataSize + DataSize;\r
- NewData = AllocateCopyPool(NewSize, OriginalData);\r
+ NewData = AllocatePool(NewSize);\r
if (NewData == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
} else {\r
if (NewData == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
} else {\r
+ CopyMem (NewData, OriginalData, OriginalSize - OriginalOptionDataSize);\r
CopyMem(NewData + OriginalSize - OriginalOptionDataSize, Data, DataSize);\r
}\r
}\r
CopyMem(NewData + OriginalSize - OriginalOptionDataSize, Data, DataSize);\r
}\r
}\r
// Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct. \r
// Re-allocate with the added information.\r
//\r
// Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct. \r
// Re-allocate with the added information.\r
//\r
- KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_INPUT_KEY) * NewKeyOption.KeyData.Options.InputKeyCount), &NewKeyOption);\r
+ KeyOptionBuffer = AllocatePool (sizeof(EFI_KEY_OPTION) + (sizeof(EFI_INPUT_KEY) * NewKeyOption.KeyData.Options.InputKeyCount));\r
if (KeyOptionBuffer == NULL) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellBcfgHiiHandle, L"bcfg"); \r
ShellStatus = SHELL_OUT_OF_RESOURCES;\r
if (KeyOptionBuffer == NULL) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellBcfgHiiHandle, L"bcfg"); \r
ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+ CopyMem (KeyOptionBuffer, &NewKeyOption, sizeof(EFI_KEY_OPTION));\r
}\r
for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < NewKeyOption.KeyData.Options.InputKeyCount; LoopCounter++) {\r
//\r
}\r
for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < NewKeyOption.KeyData.Options.InputKeyCount; LoopCounter++) {\r
//\r