Skip to content

Commit

Permalink
ShellPkg/UefiHandleParsingLib: Fix error allocate pool
Browse files Browse the repository at this point in the history
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1965

For function InsertNewGuidNameMapping, it rellocate the
mGuidList with new size
"mGuidListCount+1 * sizeof(GUID_INFO_BLOCK)". That isn't
its purpose and would cause a overflow operation in
"mGuidList[mGuidListCount - 1].xxx = xxx". Its purpose
is to increase 1 block size of mGuidList. Change it to
"(mGuidListCount + 1) * sizeof (GUID_INFO_BLOCK)".

Adjust the coding style of this function.

Cc: Jaben Carsey <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Andrew Fish <[email protected]>
Reviewed-by: Ray Ni <[email protected]>
Signed-off-by: Zhichao Gao <[email protected]>
  • Loading branch information
ZhichaoGao authored and mergify[bot] committed Dec 5, 2019
1 parent 2926498 commit 94d4efb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2462,17 +2462,21 @@ InsertNewGuidNameMapping(
IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
)
{
ASSERT(Guid != NULL);
ASSERT(NameID != 0);
ASSERT (Guid != NULL);
ASSERT (NameID != 0);

mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList);
mGuidList = ReallocatePool (
mGuidListCount * sizeof (GUID_INFO_BLOCK),
(mGuidListCount + 1) * sizeof (GUID_INFO_BLOCK),
mGuidList
);
if (mGuidList == NULL) {
mGuidListCount = 0;
return (EFI_OUT_OF_RESOURCES);
}
mGuidListCount++;

mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool (sizeof (EFI_GUID), Guid);
mGuidList[mGuidListCount - 1].StringId = NameID;
mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc;

Expand Down

0 comments on commit 94d4efb

Please sign in to comment.