From 722a438a60827f99f48d41aae3daccd8c7d73ab1 Mon Sep 17 00:00:00 2001
From: Joursoir <chat@joursoir.net>
Date: Mon, 13 Dec 2021 21:50:31 +0300
Subject: cmds: make error handling when opening a directory

---
 Library/UefiShellUfmCommandLib/cmds.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

(limited to 'Library/UefiShellUfmCommandLib')

diff --git a/Library/UefiShellUfmCommandLib/cmds.c b/Library/UefiShellUfmCommandLib/cmds.c
index 8f0b486..8a9c425 100644
--- a/Library/UefiShellUfmCommandLib/cmds.c
+++ b/Library/UefiShellUfmCommandLib/cmds.c
@@ -94,18 +94,19 @@ EFI_STATUS copy_file(CONST CHAR16 *src, CONST CHAR16 *dest)
 		if(EFI_ERROR(status))
 			return EFI_ACCESS_DENIED;
 
-		temp_name = NULL;
 		StrnCatGrow(&temp_name, &size, src, 0);
 		StrnCatGrow(&temp_name, &size, L"\\*", 0);
 		if(temp_name == NULL)
 			return EFI_OUT_OF_RESOURCES;
 
-		ShellOpenFileMetaArg(temp_name, EFI_FILE_MODE_READ, &list);
-		*temp_name = CHAR_NULL;
-		StrnCatGrow(&temp_name, &size, dest, 0);
-		StrnCatGrow(&temp_name, &size, L"\\", 0);
-		// TODO: copy directory entries
-		ShellCloseFileMetaArg(&list);
+		status = ShellOpenFileMetaArg(temp_name, EFI_FILE_MODE_READ, &list);
+		if(!EFI_ERROR(status)) {
+			*temp_name = CHAR_NULL;
+			StrnCatGrow(&temp_name, &size, dest, 0);
+			StrnCatGrow(&temp_name, &size, L"\\", 0);
+			// TODO: copy directory entries
+			ShellCloseFileMetaArg(&list);
+		}
 		SHELL_FREE_NON_NULL(temp_name);
 		return status;
 	}
-- 
cgit v1.2.3-18-g5258