All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shreenidhi Shedi <yesshedi@gmail.com>
To: grub-devel@gnu.org
Cc: yesshedi@gmail.com, alexey.makhalov@broadcom.com,
	daniel.kiper@oracle.com,
	Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Subject: [PATCH v1 2/2] cmdline: fix command line parsing in grub
Date: Sun, 18 May 2025 13:21:21 +0530	[thread overview]
Message-ID: <20250518075121.76584-3-yesshedi@gmail.com> (raw)
In-Reply-To: <20250518075121.76584-1-yesshedi@gmail.com>

From: Shreenidhi Shedi <shreenidhi.shedi@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.shedi@broadcom.com>
Reviewed-by: Alexey Makhalov  <alexey.makhalov@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

      parent reply	other threads:[~2025-05-18  8:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-18  7:51 [PATCH v1 0/2] Fix cfg file parsing and command line parsing Shreenidhi Shedi
2025-05-18  7:51 ` [PATCH v1 1/2] envblk: ignore empty new lines while parsing env files Shreenidhi Shedi
2025-05-19 17:13   ` Daniel Kiper
2025-05-19 17:25     ` Alexey Makhalov via Grub-devel
2025-05-19 18:20     ` Shreenidhi Shedi
2025-05-19 18:17   ` Vladimir 'phcoder' Serbinenko
2025-05-18  7:51 ` Shreenidhi Shedi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250518075121.76584-3-yesshedi@gmail.com \
    --to=yesshedi@gmail.com \
    --cc=alexey.makhalov@broadcom.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=shreenidhi.shedi@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.