MdePkg/UefiFileHandleLib: Fix potential NULL dereference

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

Move the NULL check in FileHandleGetInfo() to directly after the
allocation to prevent potential NULL dereferences.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Marvin Haeuser 2019-10-20 20:08:31 +08:00 committed by Liming Gao
parent 787c4baace
commit 1009b59b65
1 changed files with 15 additions and 13 deletions

View File

@ -68,19 +68,21 @@ FileHandleGetInfo (
// error is expected. getting size to allocate
//
FileInfo = AllocateZeroPool(FileInfoSize);
//
// now get the information
//
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo);
//
// if we got an error free the memory and return NULL
//
if (EFI_ERROR(Status) && (FileInfo != NULL)) {
FreePool(FileInfo);
FileInfo = NULL;
if (FileInfo != NULL) {
//
// now get the information
//
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo);
//
// if we got an error free the memory and return NULL
//
if (EFI_ERROR(Status)) {
FreePool(FileInfo);
FileInfo = NULL;
}
}
}
return (FileInfo);