Blame SOURCES/0270-blscfg-add-a-space-char-when-appending-fields-for-va.patch

c1d7cf
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c1d7cf
From: Javier Martinez Canillas <javierm@redhat.com>
c1d7cf
Date: Tue, 26 Nov 2019 09:51:41 +0100
c1d7cf
Subject: [PATCH] blscfg: add a space char when appending fields for variable
c1d7cf
 expansion
c1d7cf
c1d7cf
The GRUB variables are expanded and replaced by their values before adding
c1d7cf
menu entries, but they didn't include space characters after the values so
c1d7cf
the result was not correct.
c1d7cf
c1d7cf
For the common case this wasn't a problem but it is if there are variables
c1d7cf
that are part of the values of other variables.
c1d7cf
c1d7cf
Resolves: rhbz#1669252
c1d7cf
c1d7cf
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
c1d7cf
---
c1d7cf
 grub-core/commands/blscfg.c | 31 ++++++++++++++++++-------------
c1d7cf
 1 file changed, 18 insertions(+), 13 deletions(-)
c1d7cf
c1d7cf
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
c1d7cf
index 11cc82b6f31..c92e1c84543 100644
c1d7cf
--- a/grub-core/commands/blscfg.c
c1d7cf
+++ b/grub-core/commands/blscfg.c
c1d7cf
@@ -597,26 +597,29 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num)
c1d7cf
 
c1d7cf
 static char *field_append(bool is_var, char *buffer, char *start, char *end)
c1d7cf
 {
c1d7cf
-  char *temp = grub_strndup(start, end - start + 1);
c1d7cf
-  const char *field = temp;
c1d7cf
+  char *tmp = grub_strndup(start, end - start + 1);
c1d7cf
+  const char *field = tmp;
c1d7cf
+  int term = is_var ? 2 : 1;
c1d7cf
 
c1d7cf
   if (is_var) {
c1d7cf
-    field = grub_env_get (temp);
c1d7cf
+    field = grub_env_get (tmp);
c1d7cf
     if (!field)
c1d7cf
       return buffer;
c1d7cf
   }
c1d7cf
 
c1d7cf
-  if (!buffer) {
c1d7cf
-    buffer = grub_strdup(field);
c1d7cf
-    if (!buffer)
c1d7cf
-      return NULL;
c1d7cf
-  } else {
c1d7cf
-    buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field));
c1d7cf
-    if (!buffer)
c1d7cf
-      return NULL;
c1d7cf
+  if (!buffer)
c1d7cf
+    buffer = grub_zalloc (grub_strlen(field) + term);
c1d7cf
+  else
c1d7cf
+    buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + term);
c1d7cf
 
c1d7cf
-    grub_stpcpy (buffer + grub_strlen(buffer), field);
c1d7cf
-  }
c1d7cf
+  if (!buffer)
c1d7cf
+    return NULL;
c1d7cf
+
c1d7cf
+  tmp = buffer + grub_strlen(buffer);
c1d7cf
+  tmp = grub_stpcpy (tmp, field);
c1d7cf
+
c1d7cf
+  if (is_var)
c1d7cf
+      tmp = grub_stpcpy (tmp, " ");
c1d7cf
 
c1d7cf
   return buffer;
c1d7cf
 }
c1d7cf
@@ -646,6 +649,8 @@ static char *expand_val(char *value)
c1d7cf
 	buffer = field_append(is_var, buffer, start, end);
c1d7cf
 	is_var = false;
c1d7cf
 	start = value;
c1d7cf
+	if (*start == ' ')
c1d7cf
+	  start++;
c1d7cf
       }
c1d7cf
     }
c1d7cf