From: Shumin Qiu Date: Tue, 25 Feb 2014 08:30:32 +0000 (+0000) Subject: Add code to check whether the pointer 'CorrectedPath' and 'FullPath' are NULL before... X-Git-Tag: edk2-stable201903~11697 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=3a8406adb367e8b0d2f107adfc6c141b953d938d Add code to check whether the pointer 'CorrectedPath' and 'FullPath' are NULL before used. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Shumin Qiu Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15260 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index b5ef6aa2a9..63af5eab18 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -379,6 +379,9 @@ PrintLsOutput( } CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0); + if (CorrectedPath == NULL) { + return SHELL_OUT_OF_RESOURCES; + } if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\' &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') { CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\", 0); @@ -666,8 +669,17 @@ ShellCommandRunLs ( ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL)); if (StrStr(PathName, L":") == NULL) { StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0); + if (FullPath == NULL) { + ShellCommandLineFreeVarList (Package); + return SHELL_OUT_OF_RESOURCES; + } } StrnCatGrow(&FullPath, &Size, PathName, 0); + if (FullPath == NULL) { + ShellCommandLineFreeVarList (Package); + return SHELL_OUT_OF_RESOURCES; + } + if (ShellIsDirectory(PathName) == EFI_SUCCESS) { // // is listing ends with a directory, then we list all files in that directory