nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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