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