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

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