Blame SOURCES/0462-kern-parser-Introduce-terminate_arg-helper.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Chris Coulson <chris.coulson@canonical.com>
80913e
Date: Thu, 7 Jan 2021 19:53:55 +0000
80913e
Subject: [PATCH] kern/parser: Introduce terminate_arg() helper
80913e
80913e
process_char() and grub_parser_split_cmdline() use similar code for
80913e
terminating the most recent argument. Add a helper function for this.
80913e
80913e
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/kern/parser.c | 23 +++++++++++++----------
80913e
 1 file changed, 13 insertions(+), 10 deletions(-)
80913e
80913e
diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c
b32e65
index 0d3582bd8..572c67089 100644
80913e
--- a/grub-core/kern/parser.c
80913e
+++ b/grub-core/kern/parser.c
80913e
@@ -129,6 +129,16 @@ add_var (char *varname, char **bp, char **vp,
80913e
     *((*bp)++) = *val;
80913e
 }
80913e
 
80913e
+static void
80913e
+terminate_arg (char *buffer, char **bp, int *argc)
80913e
+{
80913e
+  if (*bp != buffer && *((*bp) - 1) != '\0')
80913e
+    {
80913e
+      *((*bp)++) = '\0';
80913e
+      (*argc)++;
80913e
+    }
80913e
+}
80913e
+
80913e
 static grub_err_t
80913e
 process_char (char c, char *buffer, char **bp, char *varname, char **vp,
80913e
 	      grub_parser_state_t state, int *argc,
80913e
@@ -157,11 +167,7 @@ process_char (char c, char *buffer, char **bp, char *varname, char **vp,
80913e
        * Don't add more than one argument if multiple
80913e
        * spaces are used.
80913e
        */
80913e
-      if (*bp != buffer && *((*bp) - 1) != '\0')
80913e
-	{
80913e
-	  *((*bp)++) = '\0';
80913e
-	  (*argc)++;
80913e
-	}
80913e
+      terminate_arg (buffer, bp, argc);
80913e
     }
80913e
   else if (use)
80913e
     *((*bp)++) = use;
80913e
@@ -232,11 +238,8 @@ grub_parser_split_cmdline (const char *cmdline,
80913e
      variable.  */
80913e
   add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT);
80913e
 
80913e
-  if (bp != buffer && *(bp - 1))
80913e
-    {
80913e
-      *(bp++) = '\0';
80913e
-      (*argc)++;
80913e
-    }
80913e
+  /* Ensure that the last argument is terminated. */
80913e
+  terminate_arg (buffer, &bp, argc);
80913e
 
80913e
   /* If there are no args, then we're done. */
80913e
   if (!*argc)