From 1009b59b6525c16724fe2684c344a6359af28b55 Mon Sep 17 00:00:00 2001 From: Marvin Haeuser Date: Sun, 20 Oct 2019 20:08:31 +0800 Subject: [PATCH] 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 Cc: Liming Gao Signed-off-by: Marvin Haeuser Reviewed-by: Liming Gao --- .../UefiFileHandleLib/UefiFileHandleLib.c | 28 ++++++++++--------- 1 file 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); -- 2.39.5