]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/rm: fix hang when deleting an absolutely-empty directory
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 8 Feb 2018 03:40:04 +0000 (11:40 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 9 Feb 2018 04:24:55 +0000 (12:24 +0800)
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>
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c

index 618610d0f3dfe9e91b2bad3a4f0745c4a2823fad..288e7666a819ef9f903a079a149f993398ed3f51 100644 (file)
@@ -2,7 +2,7 @@
   Main file for attrib shell level 2 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,6 +33,7 @@ IsDirectoryEmpty (
   IN EFI_HANDLE   FileHandle\r
   )\r
 {\r
+  EFI_STATUS      Status;\r
   EFI_FILE_INFO   *FileInfo;\r
   BOOLEAN         NoFile;\r
   BOOLEAN         RetVal;\r
@@ -41,8 +42,8 @@ IsDirectoryEmpty (
   NoFile = FALSE;\r
   FileInfo = NULL;\r
 \r
-  for (FileHandleFindFirstFile(FileHandle, &FileInfo)\r
-    ;  !NoFile\r
+  for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)\r
+    ;  !NoFile && !EFI_ERROR (Status)\r
     ;  FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)\r
    ){\r
     if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName\r