MdeModulePkg/CapsulePei: Add memory pointer check

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1935

Before use the memory that is allocated through AllocateZeroPool,
we should check the memory pointer is valid to avoid using the
NULL pointer.
Add check for VariableArrayAddress that is returned from
GetScatterGatherHeadEntries. If it is NULL, directly return
the error status.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
Gao, Zhichao 2019-06-25 11:22:49 +08:00 committed by Hao A Wu
parent c1227348e3
commit 846b1652d9
1 changed files with 5 additions and 1 deletions

View File

@ -965,6 +965,10 @@ GetScatterGatherHeadEntries (
//
if ((ValidIndex + 1) >= TempListLength) {
EnlargedTempList = AllocateZeroPool (TempListLength * 2);
if (EnlargedTempList == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory!\n"));
return EFI_OUT_OF_RESOURCES;
}
CopyMem (EnlargedTempList, TempList, TempListLength);
FreePool (TempList);
TempList = EnlargedTempList;
@ -1056,7 +1060,7 @@ CapsuleCoalesce (
// Get SG list entries
//
Status = GetScatterGatherHeadEntries (&ListLength, &VariableArrayAddress);
if (EFI_ERROR (Status)) {
if (EFI_ERROR (Status) || VariableArrayAddress == NULL) {
DEBUG ((DEBUG_ERROR, "%a failed to get Scatter Gather List Head Entries. Status = %r\n", __FUNCTION__, Status));
goto Done;
}