Skip to contentSkip to conversation

grub-core/kern/corecmd: Quote variable values when displayed by the set command

PATCH In review Glenn Washburn 2 participants 2 messages Aug 26, 2022 – Oct 6, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 grub-core/kern/corecmd: Quote variable values when displayed by the set command

Variable values may contain spaces at the end or newlines. However, when displayed without quotes this is not obvious and can lead to confusion as to the actual contents of variables. Also for some variables grub_env_get() returns a NULL pointer instead of a pointer to an empty string and previously would be printed as "var=(null)". Now such variables will be displayed as "var=''".

---
v2->v3: cast away constness when assigning var to fix compiler error

---
 grub-core/kern/corecmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/kern/corecmd.c +4 -1
index fc54f43f2b..62d434ba9a 100644
@@ -40,7 +40,10 @@ grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
     {
       struct grub_env_var *env;
       FOR_SORTED_ENV (env)
-	grub_printf ("%s=%s\n", env->name, grub_env_get (env->name));
+	{
+	  val = (char *) grub_env_get (env->name);
+	  grub_printf ("%s='%s'\n", env->name, val == NULL ? "" : val);
+	}
       return 0;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Glenn Washburn

Variable values may contain spaces at the end or newlines. However, when displayed without quotes this is not obvious and can lead to confusion as to the actual contents of variables. Also for some variables grub_env_get() returns a NULL pointer instead of a pointer to an empty string and previously would be printed as "var=(null)". Now such variables will be displayed as "var=''".

Daniel