summaryrefslogtreecommitdiff
path: root/ShellPkg/Library
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-02-08 11:40:04 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-02-09 12:24:55 +0800
commit7506fe43a10d5f8148417812d204498995d9f1e7 (patch)
tree938387761ea530f65f12ce95d57d311e3be065db /ShellPkg/Library
parent1efda6414f90c515e4ba1a8f996282f2bd322fea (diff)
downloadedk2-7506fe43a10d5f8148417812d204498995d9f1e7.zip
edk2-7506fe43a10d5f8148417812d204498995d9f1e7.tar.gz
edk2-7506fe43a10d5f8148417812d204498995d9f1e7.tar.bz2
ShellPkg/rm: fix hang when deleting an absolutely-empty directory
An ordinary empty directory should contain "." and ".." entries. When an empty directory even doesn't contain "." or ".." entry, FileHandleFindFirstFile() may return error status and a NULL FileInfo. IsDirectoryEmpty() implementation in Rm.c doesn't consider this case and the deference of FileInfo->FileName causes page fault exception because FileInfo is NULL. The patch checks the return status of FileHandleFindFirstFile() to fix this issue. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'ShellPkg/Library')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
index 618610d..288e766 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
@@ -2,7 +2,7 @@
Main file for attrib shell level 2 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
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
@@ -33,6 +33,7 @@ IsDirectoryEmpty (
IN EFI_HANDLE FileHandle
)
{
+ EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
BOOLEAN NoFile;
BOOLEAN RetVal;
@@ -41,8 +42,8 @@ IsDirectoryEmpty (
NoFile = FALSE;
FileInfo = NULL;
- for (FileHandleFindFirstFile(FileHandle, &FileInfo)
- ; !NoFile
+ for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
+ ; !NoFile && !EFI_ERROR (Status)
; FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
){
if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName