From eec0c5ccc0823b4f88bcf2c959f987ea7ede20f5 Mon Sep 17 00:00:00 2001
From: Olivier Martin <olivier.martin@arm.com>
Date: Mon, 13 Apr 2015 19:07:18 +0100
Subject: [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Handle the returned
 error

If this function fails in release build then the error was
not handled and SourceHandle was not valid.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
---
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c   |   7 +++++--
 .../UefiShellLevel2CommandsLib.uni                 | Bin 109340 -> 109570 bytes
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index ffe1ebc..8faa54b 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -170,8 +170,11 @@ CopySingleFile(
     //
     // open source file
     //
-    Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
-    ASSERT_EFI_ERROR(Status);
+    Status = ShellOpenFileByName (Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
+    if (EFI_ERROR (Status)) {
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SRC_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Source);
+      return (SHELL_ACCESS_DENIED);
+    }
 
     //
     //get file size of source file and freespace available on destination volume
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
index 048845588f0c29cc609d0b9a014a48014c598858..29563d2e21737be3c84a7e3413596a4fc8e0850b 100644
GIT binary patch
delta 65
zcmV-H0KWg6)&_#u2C&F#lOSjw4^seA07C#@08ao=07U>!lL2ZKliX!Im+mA17L$Hy
XIt6k7WdLE5(SJdM_G-8GY5^ud)w~wf

delta 22
ecmZp=!8Yd_+lCWalMme2Yrd1c{Z2Ncngale4GT&D

-- 
2.1.1

