All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUGFIX] Incorrect count of argument with rescue parser
@ 2009-07-30 22:46 Vladimir 'phcoder' Serbinenko
  2009-07-31  4:17 ` Pavel Roskin
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-30 22:46 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

This patch fixes the parsing of two strings like following ones:
"echo 1 " was parsed into "echo", "1", ""
"echo $root" was parsed into "echo" (variable just disappeared)

-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git

[-- Attachment #2: argcfix.diff --]
[-- Type: text/plain, Size: 1245 bytes --]

diff --git a/ChangeLog b/ChangeLog
index 5183b55..55372c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-07-30  Vladimir Serbinenko  <phcoder@gmail.com>
 
+	* kern/parser.c (grub_parser_split_cmdline): Fix incorrect counting
+	of arguments.
+
+2009-07-30  Vladimir Serbinenko  <phcoder@gmail.com>
+
 	* util/i386/pc/grub-setup.c (setup): Check that no partition is in
 	embeding zone, not only the first one.
 
diff --git a/kern/parser.c b/kern/parser.c
index db59af0..4f50136 100644
--- a/kern/parser.c
+++ b/kern/parser.c
@@ -142,7 +142,7 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
 	*(bp++) = *val;
     }
 
-  *argc = 1;
+  *argc = 0;
   do
     {
       if (! *rd)
@@ -188,12 +188,16 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
 	  state = newstate;
 	}
     } while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
-  *(bp++) = '\0';
 
   /* A special case for when the last character was part of a
      variable.  */
   add_var (GRUB_PARSER_STATE_TEXT);
 
+  if (bp != buffer && *(bp - 1))
+    {
+      *(bp++) = '\0';
+      (*argc)++;
+    }
 
   /* Reserve memory for the return values.  */
   args = grub_malloc (bp - buffer);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-31  9:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-30 22:46 [BUGFIX] Incorrect count of argument with rescue parser Vladimir 'phcoder' Serbinenko
2009-07-31  4:17 ` Pavel Roskin
2009-07-31  9:00   ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.