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

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