summaryrefslogtreecommitdiff
path: root/ShellPkg/Application/Shell/Shell.c
diff options
context:
space:
mode:
authorJaben Carsey <Jaben.carsey@intel.com>2015-01-27 18:56:36 +0000
committerjcarsey <jcarsey@Edk2>2015-01-27 18:56:36 +0000
commit14030c5c854ea40487a853344fc763d808c1a88b (patch)
treea5041fc9052c4f480b598b7e73d6c8e059263310 /ShellPkg/Application/Shell/Shell.c
parentfdd52bde510a5cb89ce90c307c62e617c10ab7be (diff)
downloadedk2-platforms-14030c5c854ea40487a853344fc763d808c1a88b.tar.xz
ShellPkg: refine command line parsing
Correctly divide up parameters for Argc/Argv including quote ("), escape (^), and space ( ) processing. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com> Reviewed-by: Joe Peterson <joe.peterson@intel.com> Reviewed-by: Tapan Shah <tapandshah@hp.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16673 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r--ShellPkg/Application/Shell/Shell.c90
1 files changed, 47 insertions, 43 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index a570b7b125..7eaccb747c 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1870,12 +1870,12 @@ IsValidSplit(
return (EFI_OUT_OF_RESOURCES);
}
TempWalker = (CHAR16*)Temp;
- GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine));
-
- if (GetOperationType(FirstParameter) == Unknown_Invalid) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
- SetLastError(SHELL_NOT_FOUND);
- Status = EFI_NOT_FOUND;
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine)))) {
+ if (GetOperationType(FirstParameter) == Unknown_Invalid) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
+ SetLastError(SHELL_NOT_FOUND);
+ Status = EFI_NOT_FOUND;
+ }
}
}
@@ -2030,24 +2030,25 @@ DoHelpUpdate(
Walker = *CmdLine;
while(Walker != NULL && *Walker != CHAR_NULL) {
LastWalker = Walker;
- GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine));
- if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
- LastWalker[0] = L' ';
- LastWalker[1] = L' ';
- NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));
- if (NewCommandLine == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine)))) {
+ if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
+ LastWalker[0] = L' ';
+ LastWalker[1] = L' ';
+ NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));
+ if (NewCommandLine == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // We know the space is sufficient since we just calculated it.
+ //
+ StrnCpy(NewCommandLine, L"help ", 5);
+ StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));
+ SHELL_FREE_NON_NULL(*CmdLine);
+ *CmdLine = NewCommandLine;
break;
}
-
- //
- // We know the space is sufficient since we just calculated it.
- //
- StrnCpy(NewCommandLine, L"help ", 5);
- StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));
- SHELL_FREE_NON_NULL(*CmdLine);
- *CmdLine = NewCommandLine;
- break;
}
}
@@ -2499,27 +2500,30 @@ RunCommand(
return (EFI_OUT_OF_RESOURCES);
}
TempWalker = CleanOriginal;
- GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal));
-
- //
- // Depending on the first parameter we change the behavior
- //
- switch (Type = GetOperationType(FirstParameter)) {
- case File_Sys_Change:
- Status = ChangeMappedDrive (FirstParameter);
- break;
- case Internal_Command:
- case Script_File_Name:
- case Efi_Application:
- Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);
- break;
- default:
- //
- // Whatever was typed, it was invalid.
- //
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
- SetLastError(SHELL_NOT_FOUND);
- break;
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal)))) {
+ //
+ // Depending on the first parameter we change the behavior
+ //
+ switch (Type = GetOperationType(FirstParameter)) {
+ case File_Sys_Change:
+ Status = ChangeMappedDrive (FirstParameter);
+ break;
+ case Internal_Command:
+ case Script_File_Name:
+ case Efi_Application:
+ Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);
+ break;
+ default:
+ //
+ // Whatever was typed, it was invalid.
+ //
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
+ SetLastError(SHELL_NOT_FOUND);
+ break;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
+ SetLastError(SHELL_NOT_FOUND);
}
SHELL_FREE_NON_NULL(CleanOriginal);