summaryrefslogtreecommitdiffstats
path: root/MdePkg
diff options
context:
space:
mode:
authorMarvin Haeuser <mhaeuser@outlook.de>2019-10-20 20:08:31 +0800
committerLiming Gao <liming.gao@intel.com>2019-11-04 08:52:07 +0800
commit1009b59b6525c16724fe2684c344a6359af28b55 (patch)
treea9cde1b0734ab336918116935c74e9831b0ddb92 /MdePkg
parent787c4baace1c0c49fa1628990402be8997294d17 (diff)
downloadedk2-1009b59b6525c16724fe2684c344a6359af28b55.tar.gz
edk2-1009b59b6525c16724fe2684c344a6359af28b55.tar.bz2
edk2-1009b59b6525c16724fe2684c344a6359af28b55.zip
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>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index 96913c5c02..5dc893833a 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -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);