]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fix NSH parsing
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 9 Jan 2014 18:02:26 +0000 (18:02 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 9 Jan 2014 18:02:26 +0000 (18:02 +0000)
This skips lines in NSH files that are completely comments.  This reduces the memory overhead and the later processing.

This also frees memory correctly when a second memory allocation fails.

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

ShellPkg/Application/Shell/Shell.c

index 44469baaed1f6de3e312349e7153f3dba8e40118..81982f135405a9ac442fcb3728e4bf981584aa63 100644 (file)
@@ -1067,7 +1067,7 @@ DoShellPrompt (
   if (!EFI_ERROR (Status)) {\r
     CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r
     Status = RunCommand(CmdLine);\r
-  }\r
+    }\r
 \r
   //\r
   // Done with this command\r
@@ -2362,11 +2362,13 @@ RunScriptFileHandle (
   while(!ShellFileHandleEof(Handle)) {\r
     CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);\r
     LineCount++;\r
-    if (CommandLine == NULL || StrLen(CommandLine) == 0) {\r
+    if (CommandLine == NULL || StrLen(CommandLine) == 0 || CommandLine[0] == '#') {\r
+      SHELL_FREE_NON_NULL(CommandLine);\r
       continue;\r
     }\r
     NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));\r
     if (NewScriptFile->CurrentCommand == NULL) {\r
+      SHELL_FREE_NON_NULL(CommandLine);\r
       DeleteScriptFileStruct(NewScriptFile);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r