Skip to contentSkip to conversation

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

PATCH Superseded Glenn Washburn 2 participants 3 messages Aug 16, 2022 – Aug 19, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 grub-core/kern/corecmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/corecmd.c +1 -1
index fc54f43f2..ac976e4c6 100644
@@ -40,7 +40,7 @@ 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));
+	grub_printf ("%s=\"%s\"\n", env->name, grub_env_get (env->name));
       return 0;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 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.

... but I have strange feeling I should wait a bit before merging it.

Anyway, if I do not hear any objections I will take this patch...

Quoted 9 lines
---
 grub-core/kern/corecmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/corecmd.c +0 -0
index fc54f43f2..ac976e4c6 100644

grub-core/kern/corecmd.c grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)), · line 45

Quoted 7 lines
grub-core/kern/corecmd.c +1 -1
@@ -40,7 +40,7 @@ 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));
+	grub_printf ("%s=\"%s\"\n", env->name, grub_env_get (env->name));
       return 0;
     }

Daniel

#2 lore raw
Quoted 5 lines · On Fri, 19 Aug 2022 16:03:03 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 4 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.

Quoted 7 lines
Quoted 1 line

... but I have strange feeling I should wait a bit before merging it.

Anyway, if I do not hear any objections I will take this patch...

So I have noticed that this patch can be improved. There are some variables whose value is a null pointer, not a pointer to the empty string. Before this patch, such a variable would be displayed as 'var=(null)', with this patch it gets displayed as 'var="(null)"'. I think this patch should instead print 'var=""'. Does this sound good for a v2?

Glenn

Quoted 19 lines
Quoted 10 lines
---
 grub-core/kern/corecmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/corecmd.c +0 -0
index fc54f43f2..ac976e4c6 100644

grub-core/kern/corecmd.c grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)), · line 45

Quoted 7 lines
grub-core/kern/corecmd.c +1 -1
@@ -40,7 +40,7 @@ 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));
+	grub_printf ("%s=\"%s\"\n", env->name, grub_env_get (env->name));
       return 0;
     }

Daniel