From: Shreenidhi Shedi <shreenidhi.sh...@broadcom.com>

Previously, the command line construction function
(grub_create_loader_cmdline) escaped single and double quotes, which is
unnecessary and potentially problematic since the kernel command line
handler does not support escaped quotes. This patch removes the escaping
of these characters, ensuring that the constructed command line is
passed to the kernel as intended.

For example:

In /boot/grub/grub.cfg
...
set user_cmdline="dyndbg='+p; func smp_callin -p'"
...
menuentry "Photon" {
  linux /boot/$photon_linux root=$rootpartition $photon_cmdline 
$systemd_cmdline $user_cmdline
  if [ -f /boot/$photon_initrd ]; then
    initrd /boot/$photon_initrd
  fi
}
...

Post reboot,

$ cat /proc/cmdline
... dyndbg=\'+p; func smp_callin -p\'

Signed-off-by: Shreenidhi Shedi <shreenidhi.sh...@broadcom.com>
Reviewed-by: Alexey Makhalov  <alexey.makha...@broadcom.com>
---
 grub-core/lib/cmdline.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
index ed0b149dc..57c96a151 100644
--- a/grub-core/lib/cmdline.c
+++ b/grub-core/lib/cmdline.c
@@ -22,7 +22,6 @@

 static unsigned int check_arg (char *c, int *has_space)
 {
-  int space = 0;
   unsigned int size = 0;

   while (*c)
@@ -51,15 +50,9 @@ unsigned int grub_loader_cmdline_size (int argc, char 
*argv[])
   unsigned int size = 0;

   for (i = 0; i < argc; i++)
-    {
       size += check_arg (argv[i], 0);
-      size++; /* Separator space or NULL.  */
-    }
-
-  if (size == 0)
-    size = 1;

-  return size;
+  return size ? size : 1;
 }

 grub_err_t
@@ -73,8 +66,8 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
   for (i = 0; i < argc; i++)
     {
       c = argv[i];
+      space = 0;
       arg_size = check_arg(argv[i], &space);
-      arg_size++; /* Separator space or NULL.  */

       if (size < arg_size)
        break;
@@ -86,11 +79,7 @@ grub_create_loader_cmdline (int argc, char *argv[], char 
*buf,

       while (*c)
        {
-         if (*c == '\\' || *c == '\'' || *c == '"')
-           *buf++ = '\\';
-
-         *buf++ = *c;
-         c++;
+         *buf++ = *c++;
        }

       if (space)
--
2.49.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to