From 7dd0562309ac668b7025023f05e79687fdf7a13a Mon Sep 17 00:00:00 2001 From: jcarsey Date: Fri, 22 Feb 2013 18:20:55 +0000 Subject: ShellPkg : Check pointer before dereferencing Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey Reviewed-by: Erik Bjorge git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14144 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ShellPkg') diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 5dcb294..86ac960 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -146,14 +146,16 @@ CopySingleFile( Size = 0; StrnCatGrow(&TempName, &Size, Source, 0); StrnCatGrow(&TempName, &Size, L"\\*", 0); - ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List); - *TempName = CHAR_NULL; - StrnCatGrow(&TempName, &Size, Dest, 0); - StrnCatGrow(&TempName, &Size, L"\\", 0); - ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp); - ShellCloseFileMetaArg(&List); - FreePool(TempName); - Size = 0; + if (TempName != NULL) { + ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List); + *TempName = CHAR_NULL; + StrnCatGrow(&TempName, &Size, Dest, 0); + StrnCatGrow(&TempName, &Size, L"\\", 0); + ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp); + ShellCloseFileMetaArg(&List); + SHELL_FREE_NON_NULL(TempName); + Size = 0; + } } else { // // open file with create enabled -- cgit v1.1