Grub Development Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [BUGFIX] Fix rescue parser
Date: Thu, 15 Oct 2009 15:06:42 +0200	[thread overview]
Message-ID: <4AD71E62.1010102@gmail.com> (raw)

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


-- 
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git 


[-- Attachment #2: parres.diff --]
[-- Type: text/x-patch, Size: 3416 bytes --]

diff --git a/ChangeLog b/ChangeLog
index b0864a9..55bdc92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
 
+	* kern/parser.c (grub_parser_split_cmdline): Fix incorrect counting
+	of arguments. Return number of tokens and not arguments. All users
+	updated.
+
+2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
+
 	* loader/i386/pc/xnu.c (grub_xnu_set_video): Fix loading splash image.
 
 2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
diff --git a/kern/parser.c b/kern/parser.c
index db59af0..006d67d 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);
@@ -219,8 +223,6 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
       bp++;
     }
 
-  (*argc)--;
-
   return 0;
 }
 
diff --git a/kern/rescue_parser.c b/kern/rescue_parser.c
index 1e0841e..d3725e7 100644
--- a/kern/rescue_parser.c
+++ b/kern/rescue_parser.c
@@ -35,9 +35,12 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
   if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0)
     return grub_errno;
 
+  if (n == 0)
+    return GRUB_ERR_NONE;
+
   /* In case of an assignment set the environment accordingly
      instead of calling a function.  */
-  if (n == 0 && grub_strchr (line, '='))
+  if (n == 1 && grub_strchr (line, '='))
     {
       char *val = grub_strchr (args[0], '=');
       val[0] = 0;
@@ -56,7 +59,7 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
   cmd = grub_command_find (name);
   if (cmd)
     {
-      (cmd->func) (cmd, n, &args[1]);
+      (cmd->func) (cmd, n - 1, &args[1]);
     }
   else
     {
diff --git a/normal/completion.c b/normal/completion.c
index 4b38e33..d264028 100644
--- a/normal/completion.c
+++ b/normal/completion.c
@@ -409,13 +409,16 @@ grub_normal_do_completion (char *buf, int *restore,
   if (grub_parser_split_cmdline (buf, 0, &argc, &argv))
     return 0;
 
-  current_word = argv[argc];
+  if (argc == 0)
+    current_word = "";
+  else
+    current_word = argv[argc - 1];
 
   /* Determine the state the command line is in, depending on the
      state, it can be determined how to complete.  */
   cmdline_state = get_state (buf);
 
-  if (argc == 0)
+  if (argc == 1 || argc == 0)
     {
       /* Complete a command.  */
       if (grub_command_iterate (iterate_command))
@@ -485,13 +488,15 @@ grub_normal_do_completion (char *buf, int *restore,
           goto fail;
 	}
 
-      grub_free (argv[0]);
+      if (argc != 0)
+	grub_free (argv[0]);
       grub_free (match);
       return ret;
     }
 
  fail:
-  grub_free (argv[0]);
+  if (argc != 0)
+    grub_free (argv[0]);
   grub_free (match);
   grub_errno = GRUB_ERR_NONE;
 

             reply	other threads:[~2009-10-15 13:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-15 13:06 Vladimir 'phcoder' Serbinenko [this message]
2009-10-16 18:34 ` [BUGFIX] Fix rescue parser Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AD71E62.1010102@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox