Revision: 16126
          http://sourceforge.net/p/edk2/code/16126
Author:   shenshushi
Date:     2014-09-18 01:21:01 +0000 (Thu, 18 Sep 2014)
Log Message:
-----------
ShellPkg: Fix the support for command line comments.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <[email protected]>
Reviewed-by: Chris Phillips <[email protected]>
Reviewed-by: Jaben Carsey <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/Shell.c
    trunk/edk2/ShellPkg/Application/Shell/ShellProtocol.c

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c       2014-09-17 20:58:16 UTC 
(rev 16125)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c       2014-09-18 01:21:01 UTC 
(rev 16126)
@@ -2139,11 +2139,24 @@
   CHAR16                    **Argv;
   SHELL_STATUS              CommandReturnedStatus;
   BOOLEAN                   LastError;
+  CHAR16                    *Walker;
+  CHAR16                    *NewCmdLine;  
 
+  NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);
+  if (NewCmdLine == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) 
{
+    if (*Walker == L'^' && *(Walker+1) == L'#') {
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
+    }
+  }
+
   //
   // get the argc and argv updated for internal commands
   //
-  Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);
+  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, &Argv, &Argc);
   if (!EFI_ERROR(Status)) {
     //
     // Run the internal command.
@@ -2204,6 +2217,7 @@
     Status = EFI_SUCCESS;
   }
 
+  FreePool (NewCmdLine);
   return (Status);
 }
 
@@ -2466,7 +2480,7 @@
   for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != 
CHAR_NULL; TempWalker++) {
     if (*TempWalker == L'^') {
       if (*(TempWalker + 1) == L'#') {
-        CopyMem (TempWalker, TempWalker + 1, StrSize (TempWalker) - sizeof 
(TempWalker[0]));
+        TempWalker++;
       }
     } else if (*TempWalker == L'#') {
       *TempWalker = CHAR_NULL;
@@ -2710,8 +2724,10 @@
     //
     for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 
!= CHAR_NULL ; CommandLine3++) {
       if (*CommandLine3 == L'^') {
-        if (*(CommandLine3+1) == L'#' || *(CommandLine3+1) == L':') {
+        if ( *(CommandLine3+1) == L':') {
           CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - 
sizeof(CommandLine3[0]));
+        } else if (*(CommandLine3+1) == L'#') {
+          CommandLine3++;
         }
       } else if (*CommandLine3 == L'#') {
         *CommandLine3 = CHAR_NULL;

Modified: trunk/edk2/ShellPkg/Application/Shell/ShellProtocol.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/ShellProtocol.c       2014-09-17 
20:58:16 UTC (rev 16125)
+++ trunk/edk2/ShellPkg/Application/Shell/ShellProtocol.c       2014-09-18 
01:21:01 UTC (rev 16126)
@@ -1433,6 +1433,8 @@
   UINTN                         *ExitDataSizePtr;
   CHAR16                        *ImagePath;
   UINTN                         Index;
+  CHAR16                        *Walker;
+  CHAR16                        *NewCmdLine;
 
   // ExitDataSize is not OPTIONAL for gBS->BootServices, provide somewhere for
   // it to be dumped if the caller doesn't want it.
@@ -1449,7 +1451,18 @@
   InitializeListHead(&OrigEnvs);
 
   NewHandle = NULL;
+  
+  NewCmdLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);
+  if (NewCmdLine == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
 
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) 
{
+    if (*Walker == L'^' && *(Walker+1) == L'#') {
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
+    }
+  }
+
   //
   // Load the image with:
   // FALSE - not from boot manager and NULL, 0 being not already in memory
@@ -1478,9 +1491,9 @@
 
   if (!EFI_ERROR(Status)) {
     ASSERT(LoadedImage->LoadOptionsSize == 0);
-    if (CommandLine != NULL) {
-      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(CommandLine);
-      LoadedImage->LoadOptions      = (VOID*)CommandLine;
+    if (NewCmdLine != NULL) {
+      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(NewCmdLine);
+      LoadedImage->LoadOptions      = (VOID*)NewCmdLine;
     }
 
     //
@@ -1499,7 +1512,7 @@
     ShellParamsProtocol.StdIn   = 
ShellInfoObject.NewShellParametersProtocol->StdIn;
     ShellParamsProtocol.StdOut  = 
ShellInfoObject.NewShellParametersProtocol->StdOut;
     ShellParamsProtocol.StdErr  = 
ShellInfoObject.NewShellParametersProtocol->StdErr;
-    Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);
+    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, NULL, NULL);
     ASSERT_EFI_ERROR(Status);
     //
     // Replace Argv[0] with the full path of the binary we're executing:
@@ -1578,6 +1591,8 @@
     ASSERT_EFI_ERROR (CleanupStatus);
   }
 
+  FreePool (NewCmdLine);
+
   return(Status);
 }
 /**


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to