ShellPkg: Fix Shell ASSERT when mv file with cwd is NULL.

Shell will ASSERT when doing the following operation:
""
Shell> mv fs2:\file1 fs2:\file2
""
This patch add NULL pointer check to fix this issue.

Fixes: https://github.com/tianocore/edk2/issues/76

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
Qiu Shumin 2016-04-08 15:41:06 +08:00
parent 800c02fbe2
commit 64ee6ed72a
1 changed files with 16 additions and 13 deletions

View File

@ -483,7 +483,9 @@ ValidateAndMoveFiles(
Response = *Resp; Response = *Resp;
Attr = 0; Attr = 0;
CleanFilePathStr = NULL; CleanFilePathStr = NULL;
FullCwd = NULL;
if (Cwd != NULL) {
FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16)); FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));
if (FullCwd == NULL) { if (FullCwd == NULL) {
return SHELL_OUT_OF_RESOURCES; return SHELL_OUT_OF_RESOURCES;
@ -491,10 +493,11 @@ ValidateAndMoveFiles(
StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd); StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);
StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\"); StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");
} }
}
Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr); Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool (FullCwd); SHELL_FREE_NON_NULL(FullCwd);
if (Status == EFI_OUT_OF_RESOURCES) { if (Status == EFI_OUT_OF_RESOURCES) {
return SHELL_OUT_OF_RESOURCES; return SHELL_OUT_OF_RESOURCES;
} else { } else {
@ -511,7 +514,7 @@ ValidateAndMoveFiles(
FreePool (CleanFilePathStr); FreePool (CleanFilePathStr);
if (ShellStatus != SHELL_SUCCESS) { if (ShellStatus != SHELL_SUCCESS) {
FreePool (FullCwd); SHELL_FREE_NON_NULL (FullCwd);
return (ShellStatus); return (ShellStatus);
} }
DestPath = PathCleanUpDirectories(DestPath); DestPath = PathCleanUpDirectories(DestPath);
@ -526,7 +529,7 @@ ValidateAndMoveFiles(
SHELL_FREE_NON_NULL(DestPath); SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput); SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk); SHELL_FREE_NON_NULL(HiiResultOk);
FreePool (FullCwd); SHELL_FREE_NON_NULL(FullCwd);
return (SHELL_OUT_OF_RESOURCES); return (SHELL_OUT_OF_RESOURCES);
} }
@ -588,7 +591,7 @@ ValidateAndMoveFiles(
// //
// indicate to stop everything // indicate to stop everything
// //
FreePool(FullCwd); SHELL_FREE_NON_NULL(FullCwd);
return (SHELL_ABORTED); return (SHELL_ABORTED);
case ShellPromptResponseAll: case ShellPromptResponseAll:
*Resp = Response; *Resp = Response;
@ -599,7 +602,7 @@ ValidateAndMoveFiles(
break; break;
default: default:
FreePool(Response); FreePool(Response);
FreePool(FullCwd); SHELL_FREE_NON_NULL(FullCwd);
return SHELL_ABORTED; return SHELL_ABORTED;
} }
Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath); Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath);
@ -646,7 +649,7 @@ ValidateAndMoveFiles(
SHELL_FREE_NON_NULL(DestPath); SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput); SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk); SHELL_FREE_NON_NULL(HiiResultOk);
FreePool (FullCwd); SHELL_FREE_NON_NULL(FullCwd);
return (ShellStatus); return (ShellStatus);
} }