nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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