]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Don't strip positional parameters of quotation marks.
authorQiu Shumin <shumin.qiu@intel.com>
Mon, 9 Nov 2015 02:29:31 +0000 (02:29 +0000)
committershenshushi <shenshushi@Edk2>
Mon, 9 Nov 2015 02:29:31 +0000 (02:29 +0000)
Per Shell SPEC 2.1 'Double-quotation marks that surround arguments are not stripped in positional parameters'. This patch makes Shell implementation to follow SPEC.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18742 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/Shell.h
ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg/Application/Shell/ShellParametersProtocol.h
ShellPkg/Application/Shell/ShellProtocol.c

index cb9d969441506981e1587a66b16be3261bb9a3e8..8af66479a3b40135972bae96532b89756b5c22e9 100644 (file)
@@ -1863,7 +1863,7 @@ IsValidSplit(
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
     TempWalker = (CHAR16*)Temp;\r
-    if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine)))) {\r
+    if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine), TRUE))) {\r
       if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
         SetLastError(SHELL_NOT_FOUND);\r
@@ -2029,7 +2029,7 @@ DoHelpUpdate(
 \r
   Walker = *CmdLine;\r
   while(Walker != NULL && *Walker != CHAR_NULL) {\r
-    if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine)))) {\r
+    if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine), TRUE))) {\r
       if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
         CurrentParameter[0] = L' ';\r
         CurrentParameter[1] = L' ';\r
@@ -2173,7 +2173,7 @@ RunInternalCommand(
   //\r
   // get the argc and argv updated for internal commands\r
   //\r
-  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, &Argv, &Argc);\r
+  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, Internal_Command, &Argv, &Argc);\r
   if (!EFI_ERROR(Status)) {\r
     //\r
     // Run the internal command.\r
@@ -2520,7 +2520,7 @@ RunShellCommand(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   TempWalker = CleanOriginal;\r
-  if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal)))) {\r
+  if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal), TRUE))) {\r
     //\r
     // Depending on the first parameter we change the behavior\r
     //\r
@@ -2767,34 +2767,34 @@ RunScriptFileHandle (
       if (NewScriptFile->Argv != NULL) {\r
         switch (NewScriptFile->Argc) {\r
           default:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%9", NewScriptFile->Argv[9], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%9", NewScriptFile->Argv[9], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 9:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%8", NewScriptFile->Argv[8], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%8", NewScriptFile->Argv[8], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 8:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%7", NewScriptFile->Argv[7], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%7", NewScriptFile->Argv[7], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 7:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%6", NewScriptFile->Argv[6], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%6", NewScriptFile->Argv[6], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 6:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%5", NewScriptFile->Argv[5], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%5", NewScriptFile->Argv[5], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 5:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%4", NewScriptFile->Argv[4], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%4", NewScriptFile->Argv[4], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 4:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%3", NewScriptFile->Argv[3], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%3", NewScriptFile->Argv[3], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 3:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%2", NewScriptFile->Argv[2], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%2", NewScriptFile->Argv[2], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 2:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%1", NewScriptFile->Argv[1], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%1", NewScriptFile->Argv[1], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 1:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%0", NewScriptFile->Argv[0], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%0", NewScriptFile->Argv[0], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
             break;\r
           case 0:\r
@@ -2944,7 +2944,7 @@ RunScriptFile (
   //\r
   // get the argc and argv updated for scripts\r
   //\r
-  Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);\r
+  Status = UpdateArgcArgv(ParamProtocol, CmdLine, Script_File_Name, &Argv, &Argc);\r
   if (!EFI_ERROR(Status)) {\r
 \r
     if (Handle == NULL) {\r
index 7c876510dd29f5d80ee08c9b3b361597414a251f..57263204e388e86c61e0488e9d85ce7852580b9a 100644 (file)
@@ -124,14 +124,6 @@ typedef struct {
 \r
 extern SHELL_INFO ShellInfoObject;\r
 \r
-typedef enum {\r
-  Internal_Command,\r
-  Script_File_Name,\r
-  Efi_Application,\r
-  File_Sys_Change,\r
-  Unknown_Invalid\r
-} SHELL_OPERATION_TYPES;\r
-\r
 /**\r
   Converts the command line to it's post-processed form.  this replaces variables and alias' per UEFI Shell spec.\r
 \r
index 9c502f8f212e70290706b18c874b02582bb8fbb4..56dd79214b3ad8363cb396190d06095cf91af560 100644 (file)
@@ -74,10 +74,12 @@ FindEndOfParameter(
 \r
   This will also remove all remaining ^ characters after processing.\r
 \r
-  @param[in, out] Walker        pointer to string of command line.  Adjusted to\r
-                                reminaing command line on return\r
-  @param[in, out] TempParameter pointer to string of command line item extracted.\r
-  @param[in]      Length        buffer size of TempParameter.\r
+  @param[in, out] Walker          pointer to string of command line.  Adjusted to\r
+                                  reminaing command line on return\r
+  @param[in, out] TempParameter   pointer to string of command line item extracted.\r
+  @param[in]      Length          buffer size of TempParameter.\r
+  @param[in]      StripQuotation  if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
 \r
   @return   EFI_INALID_PARAMETER  A required parameter was NULL or pointed to a NULL or empty string.\r
   @return   EFI_NOT_FOUND         A closing " could not be found on the specified string\r
@@ -87,7 +89,8 @@ EFIAPI
 GetNextParameter(\r
   IN OUT CHAR16   **Walker,\r
   IN OUT CHAR16   **TempParameter,\r
-  IN CONST UINTN  Length\r
+  IN CONST UINTN  Length,\r
+  IN BOOLEAN      StripQuotation\r
   )\r
 {\r
   CONST CHAR16 *NextDelim;\r
@@ -161,7 +164,11 @@ DEBUG_CODE_END();
       //\r
       // eliminate the unescaped quote\r
       //\r
-      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+      if (StripQuotation) {\r
+        CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+         } else{\r
+        NextDelim++;\r
+         }\r
     }\r
   }\r
 \r
@@ -178,9 +185,11 @@ DEBUG_CODE_END();
   All special character processing (alias, environment variable, redirection, \r
   etc... must be complete before calling this API.\r
 \r
-  @param[in] CommandLine         String of command line to parse\r
-  @param[in, out] Argv           pointer to array of strings; one for each parameter\r
-  @param[in, out] Argc           pointer to number of strings in Argv array\r
+  @param[in] CommandLine          String of command line to parse\r
+  @param[in] StripQuotation       if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
+  @param[in, out] Argv            pointer to array of strings; one for each parameter\r
+  @param[in, out] Argc            pointer to number of strings in Argv array\r
 \r
   @return EFI_SUCCESS           the operation was sucessful\r
   @return EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
@@ -189,8 +198,9 @@ EFI_STATUS
 EFIAPI\r
 ParseCommandLineToArgs(\r
   IN CONST CHAR16 *CommandLine,\r
-  IN OUT CHAR16 ***Argv,\r
-  IN OUT UINTN *Argc\r
+  IN BOOLEAN      StripQuotation,\r
+  IN OUT CHAR16   ***Argv,\r
+  IN OUT UINTN    *Argc\r
   )\r
 {\r
   UINTN       Count;\r
@@ -228,7 +238,7 @@ ParseCommandLineToArgs(
       ; Walker != NULL && *Walker != CHAR_NULL\r
       ; Count++\r
       ) {\r
-    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {\r
+    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {\r
       break;\r
     }\r
   }\r
@@ -246,7 +256,7 @@ ParseCommandLineToArgs(
   Walker = (CHAR16*)NewCommandLine;\r
   while(Walker != NULL && *Walker != CHAR_NULL) {\r
     SetMem16(TempParameter, Size, CHAR_NULL);\r
-    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {\r
+    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
@@ -375,6 +385,7 @@ CreatePopulateInstallShellParametersProtocol (
     // Populate Argc and Argv\r
     //\r
     Status = ParseCommandLineToArgs(FullCommandLine,\r
+                                    TRUE,\r
                                     &(*NewShellParameters)->Argv,\r
                                     &(*NewShellParameters)->Argc);\r
 \r
@@ -1369,6 +1380,7 @@ RestoreStdInStdOutStdErr (
 \r
   @param[in, out] ShellParameters        Pointer to parameter structure to modify.\r
   @param[in] NewCommandLine              The new command line to parse and use.\r
+  @param[in] Type                        The type of operation.\r
   @param[out] OldArgv                    Pointer to old list of parameters.\r
   @param[out] OldArgc                    Pointer to old number of items in Argv list.\r
 \r
@@ -1380,11 +1392,15 @@ EFIAPI
 UpdateArgcArgv(\r
   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,\r
   IN CONST CHAR16                       *NewCommandLine,\r
+  IN SHELL_OPERATION_TYPES              Type,\r
   OUT CHAR16                            ***OldArgv OPTIONAL,\r
   OUT UINTN                             *OldArgc OPTIONAL\r
   )\r
 {\r
+  BOOLEAN                 StripParamQuotation;\r
+  \r
   ASSERT(ShellParameters != NULL);\r
+  StripParamQuotation = TRUE;\r
 \r
   if (OldArgc != NULL) {\r
     *OldArgc = ShellParameters->Argc;\r
@@ -1393,7 +1409,15 @@ UpdateArgcArgv(
     *OldArgv = ShellParameters->Argv;\r
   }\r
 \r
-  return (ParseCommandLineToArgs(NewCommandLine, &(ShellParameters->Argv), &(ShellParameters->Argc)));\r
+  if (Type == Script_File_Name) {\r
+    StripParamQuotation = FALSE;\r
+  }\r
+  \r
+  return ParseCommandLineToArgs( NewCommandLine, \r
+                                 StripParamQuotation, \r
+                                 &(ShellParameters->Argv), \r
+                                 &(ShellParameters->Argc)\r
+                                );\r
 }\r
 \r
 /**\r
index 2fd8f8c88b3318c91e39f1be597957f1d85288a8..926f36242cdee50e152e33d7419a700dac6e7cf0 100644 (file)
 \r
 #include "Shell.h"\r
 \r
+typedef enum {\r
+  Internal_Command,\r
+  Script_File_Name,\r
+  Efi_Application,\r
+  File_Sys_Change,\r
+  Unknown_Invalid\r
+} SHELL_OPERATION_TYPES;\r
+\r
 /**\r
   creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then\r
   installs it on our handle and if there is an existing version of the protocol\r
@@ -66,6 +74,7 @@ CleanUpShellParametersProtocol (
 \r
   @param[in, out] ShellParameters       pointer to parameter structure to modify\r
   @param[in] NewCommandLine             the new command line to parse and use\r
+  @param[in] Type                       the type of operation.\r
   @param[out] OldArgv                   pointer to old list of parameters\r
   @param[out] OldArgc                   pointer to old number of items in Argv list\r
 \r
@@ -77,6 +86,7 @@ EFIAPI
 UpdateArgcArgv(\r
   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,\r
   IN CONST CHAR16                       *NewCommandLine,\r
+  IN SHELL_OPERATION_TYPES              Type,\r
   OUT CHAR16                            ***OldArgv,\r
   OUT UINTN                             *OldArgc\r
   );\r
@@ -162,9 +172,11 @@ RestoreStdInStdOutStdErr (
   parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL.  this supports space\r
   delimited and quote surrounded parameter definition.\r
 \r
-  @param[in] CommandLine         String of command line to parse\r
-  @param[in, out] Argv           pointer to array of strings; one for each parameter\r
-  @param[in, out] Argc           pointer to number of strings in Argv array\r
+  @param[in] CommandLine          String of command line to parse\r
+  @param[in] StripQuotation       if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
+  @param[in, out] Argv            pointer to array of strings; one for each parameter\r
+  @param[in, out] Argc            pointer to number of strings in Argv array\r
 \r
   @return EFI_SUCCESS           the operation was sucessful\r
   @return EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
@@ -173,8 +185,9 @@ EFI_STATUS
 EFIAPI\r
 ParseCommandLineToArgs(\r
   IN CONST CHAR16 *CommandLine,\r
-  IN OUT CHAR16 ***Argv,\r
-  IN OUT UINTN *Argc\r
+  IN BOOLEAN      StripQuotation,\r
+  IN OUT CHAR16   ***Argv,\r
+  IN OUT UINTN    *Argc\r
   );\r
 \r
 /**\r
@@ -187,10 +200,12 @@ ParseCommandLineToArgs(
   Temp Parameter must be large enough to hold the parameter before calling this\r
   function.\r
 \r
-  @param[in, out] Walker        pointer to string of command line.  Adjusted to\r
-                                reminaing command line on return\r
-  @param[in, out] TempParameter pointer to string of command line item extracted.\r
-  @param[in]      Length        Length of (*TempParameter) in bytes\r
+  @param[in, out] Walker          pointer to string of command line.  Adjusted to\r
+                                  reminaing command line on return\r
+  @param[in, out] TempParameter   pointer to string of command line item extracted.\r
+  @param[in]      Length          Length of (*TempParameter) in bytes\r
+  @param[in]      StripQuotation  if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
 \r
   @return   EFI_INALID_PARAMETER  A required parameter was NULL or pointed to a NULL or empty string.\r
   @return   EFI_NOT_FOUND         A closing " could not be found on the specified string\r
@@ -200,7 +215,8 @@ EFIAPI
 GetNextParameter(\r
   IN OUT CHAR16   **Walker,\r
   IN OUT CHAR16   **TempParameter,\r
-  IN CONST UINTN  Length\r
+  IN CONST UINTN  Length,\r
+  IN BOOLEAN      StripQuotation\r
   );\r
 \r
 #endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
index fc13595dbb038727ce04564b4b9f5e4ac8023c2a..9c370ccef5afc938e86d1801167bdc6ada476986 100644 (file)
@@ -1501,7 +1501,7 @@ InternalShellExecuteDevicePath(
     ShellParamsProtocol.StdIn   = ShellInfoObject.NewShellParametersProtocol->StdIn;\r
     ShellParamsProtocol.StdOut  = ShellInfoObject.NewShellParametersProtocol->StdOut;\r
     ShellParamsProtocol.StdErr  = ShellInfoObject.NewShellParametersProtocol->StdErr;\r
-    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, NULL, NULL);\r
+    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, Efi_Application, NULL, NULL);\r
     ASSERT_EFI_ERROR(Status);\r
     //\r
     // Replace Argv[0] with the full path of the binary we're executing:\r