lib/misc: avoid NULL dereference in LibInsertToTailOfBootOrder

AllocatePool() may return NULL. We must check the return value before
dereferencing it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Heinrich Schuchardt 2021-06-21 22:03:18 +00:00
parent 70402aa91d
commit 500c10f191

View File

@ -386,7 +386,9 @@ LibInsertToTailOfBootOrder (
VarSize += sizeof(UINT16);
NewBootOptionArray = AllocatePool (VarSize);
if (!NewBootOptionArray)
return EFI_OUT_OF_RESOURCES;
for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) {
NewBootOptionArray[Index] = BootOptionArray[Index];
}
@ -403,9 +405,7 @@ LibInsertToTailOfBootOrder (
VarSize, (VOID*) NewBootOptionArray
);
if (NewBootOptionArray) {
FreePool (NewBootOptionArray);
}
FreePool (NewBootOptionArray);
if (BootOptionArray) {
FreePool (BootOptionArray);
}