]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg: Fix the support for command line comments.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index 692e42b7372cd60708e4649c2dfb08cd8fdf29d9..11f5d481f9b0f19e61eb240859eeed5490dd6252 100644 (file)
@@ -1433,6 +1433,8 @@ InternalShellExecuteDevicePath(
   UINTN                         *ExitDataSizePtr;\r
   CHAR16                        *ImagePath;\r
   UINTN                         Index;\r
+  CHAR16                        *Walker;\r
+  CHAR16                        *NewCmdLine;\r
 \r
   // ExitDataSize is not OPTIONAL for gBS->BootServices, provide somewhere for\r
   // it to be dumped if the caller doesn't want it.\r
@@ -1449,6 +1451,17 @@ InternalShellExecuteDevicePath(
   InitializeListHead(&OrigEnvs);\r
 \r
   NewHandle = NULL;\r
+  \r
+  NewCmdLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);\r
+  if (NewCmdLine == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+    if (*Walker == L'^' && *(Walker+1) == L'#') {\r
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+    }\r
+  }\r
 \r
   //\r
   // Load the image with:\r
@@ -1478,9 +1491,9 @@ InternalShellExecuteDevicePath(
 \r
   if (!EFI_ERROR(Status)) {\r
     ASSERT(LoadedImage->LoadOptionsSize == 0);\r
-    if (CommandLine != NULL) {\r
-      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(CommandLine);\r
-      LoadedImage->LoadOptions      = (VOID*)CommandLine;\r
+    if (NewCmdLine != NULL) {\r
+      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(NewCmdLine);\r
+      LoadedImage->LoadOptions      = (VOID*)NewCmdLine;\r
     }\r
 \r
     //\r
@@ -1499,7 +1512,7 @@ InternalShellExecuteDevicePath(
     ShellParamsProtocol.StdIn   = ShellInfoObject.NewShellParametersProtocol->StdIn;\r
     ShellParamsProtocol.StdOut  = ShellInfoObject.NewShellParametersProtocol->StdOut;\r
     ShellParamsProtocol.StdErr  = ShellInfoObject.NewShellParametersProtocol->StdErr;\r
-    Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);\r
+    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, NULL, NULL);\r
     ASSERT_EFI_ERROR(Status);\r
     //\r
     // Replace Argv[0] with the full path of the binary we're executing:\r
@@ -1578,6 +1591,8 @@ FreeAlloc:
     ASSERT_EFI_ERROR (CleanupStatus);\r
   }\r
 \r
+  FreePool (NewCmdLine);\r
+\r
   return(Status);\r
 }\r
 /**\r