From d32e3a0bc63d3bd15aa1fa5f708d71fcab57ea90 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Wed, 13 Jul 2016 15:44:23 +0800 Subject: ShellPkg/DrvCfg: Handle memory allocation failure Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Reviewed-by: Jaben Carsey (cherry picked from commit 58972f5cf7e1163e474f961afe34e200fd5dac11) --- ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'ShellPkg/Library/UefiShellDriver1CommandsLib') diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c index 609d076da0..0d12f01199 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c @@ -2,7 +2,7 @@ Main file for DrvCfg shell Driver1 function. (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -57,8 +57,11 @@ FindHiiHandleViaDevPath( Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer); if (Status == EFI_BUFFER_TOO_SMALL) { HandleBuffer = AllocateZeroPool(HandleBufferSize); - ASSERT (HandleBuffer != NULL); - Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer); + if (HandleBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = HiiDb->ListPackageLists (HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer); + } } if (EFI_ERROR(Status)) { SHELL_FREE_NON_NULL(HandleBuffer); @@ -75,8 +78,12 @@ FindHiiHandleViaDevPath( Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer); if (Status == EFI_BUFFER_TOO_SMALL) { MainBuffer = AllocateZeroPool(MainBufferSize); - ASSERT (MainBuffer != NULL); - Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer); + if (MainBuffer != NULL) { + Status = HiiDb->ExportPackageLists (HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer); + } + } + if (EFI_ERROR (Status)) { + continue; } // // Enumerate through the block of returned memory. -- cgit v1.2.3