All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lunar <lunar@torproject.org>
To: grub-devel@gnu.org
Subject: Re: [bug #44239] Behavior of syslinux_parse differs from SYSLINUX for initrd= option
Date: Fri, 13 Feb 2015 21:32:32 +0100	[thread overview]
Message-ID: <20150213203232.GG688@loar> (raw)
In-Reply-To: <20150213-191419.sv89796.29507@savannah.gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 456 bytes --]

Andrei Borzenkov:
> Follow-up Comment #1, bug #44239 (project grub):
> 
> Can't comment about behavior itself. Re. patch
> 
> +	cmdline = grub_strdup(curentry->append);
> Error check missing.
> 
> +	grub_free(cmdline);
> You need to delete free(cmdline) later.

Both fixed.

> Again, can you post updated version to grub-devel for easier review?

Here it is.

-- 
Lunar                                             <lunar@torproject.org>

[-- Attachment #1.2: 0002-lib-syslinux_parse-keep-initrd-in-kernel-the-command.patch --]
[-- Type: text/x-diff, Size: 2644 bytes --]

From d1a88855eea4b2b3099d8ad8ff689305f74736cd Mon Sep 17 00:00:00 2001
From: Lunar <lunar@torproject.org>
Date: Sat, 14 Feb 2015 16:50:14 +0100
Subject: [PATCH 2/2] lib/syslinux_parse: keep initrd= in kernel the command
 line

SYSLINUX parses but does not remove "initrd=..." option from the kernel
command line. As some distributions (e.g. Tails) rely on its
presence, let's keep the same behavior.

Fixes Savannah bug #44239.
---
 grub-core/lib/syslinux_parse.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c
index b0d5f9e..1318c3a 100644
--- a/grub-core/lib/syslinux_parse.c
+++ b/grub-core/lib/syslinux_parse.c
@@ -939,6 +939,9 @@ write_entry (struct output_buffer *outbuf,
 	char *ptr;
 	char *cmdline;
 	char *initrd = NULL;
+	cmdline = grub_strdup(curentry->append ? curentry->append : "");
+	if (!cmdline)
+	  return grub_errno;
 	for (ptr = curentry->append; ptr && *ptr; ptr++)
 	  if ((ptr == curentry->append || grub_isspace (ptr[-1]))
 	      && grub_strncasecmp (ptr, "initrd=", sizeof ("initrd=") - 1)
@@ -946,32 +949,16 @@ write_entry (struct output_buffer *outbuf,
 	    break;
 	if (ptr && *ptr)
 	  {
-	    char *ptr2;
-	    grub_size_t totlen = grub_strlen (curentry->append);
 	    initrd = ptr + sizeof ("initrd=") - 1;
-	    for (ptr2 = ptr; *ptr2 && !grub_isspace (*ptr2); ptr2++);
-	    if (*ptr2)
-	      {
-		*ptr2 = 0;
-		ptr2++;
-	      }
-	    cmdline = grub_malloc (totlen + 1 - (ptr2 - ptr));
-	    if (!cmdline)
-	      return grub_errno;
-	    grub_memcpy (cmdline, curentry->append, ptr - curentry->append);
-	    grub_memcpy (cmdline + (ptr - curentry->append),
-			 ptr2, totlen - (ptr2 - curentry->append));
-	    *(cmdline + totlen - (ptr2 - ptr)) = 0;
+	    for (; *ptr && !grub_isspace (*ptr); ptr++);
+	    *ptr = '\0';
 	  }
-	else
-	  cmdline = curentry->append;
 	print_string (" if test x$grub_platform = xpc; then "
 		      "linux_suffix=16; else linux_suffix= ; fi\n");
 	print_string ("  linux$linux_suffix ");
 	print_file (outbuf, menu, curentry->kernel_file, NULL);
 	print_string (" ");
-	if (cmdline)
-	  print (outbuf, cmdline, grub_strlen (cmdline));
+	print (outbuf, cmdline, grub_strlen (cmdline));
 	print_string ("\n");
 	if (initrd || curentry->initrds)
 	  {
@@ -990,8 +977,7 @@ write_entry (struct output_buffer *outbuf,
 
 	    print_string ("\n");
 	  }
-	if (ptr && *ptr)
-	  grub_free (cmdline);
+	grub_free (cmdline);
       }
       break;
     case KERNEL_CHAINLOADER:
-- 
1.9.1


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

       reply	other threads:[~2015-02-13 20:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150213-163645.sv98365.99674@savannah.gnu.org>
     [not found] ` <20150213-191419.sv89796.29507@savannah.gnu.org>
2015-02-13 20:32   ` Lunar [this message]
2015-02-16 15:07     ` [bug #44239] Behavior of syslinux_parse differs from SYSLINUX for initrd= option Vladimir 'φ-coder/phcoder' Serbinenko

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=20150213203232.GG688@loar \
    --to=lunar@torproject.org \
    --cc=grub-devel@gnu.org \
    /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.