Blob Blame History Raw
From e29af836d02a267d6ad9bd6eba808d5bf0a96949 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Mon, 16 Feb 2015 15:56:26 +0100
Subject: [PATCH 289/506] Don't remove initrd= parameter.

Based on simplified patch by Lunar.

Reported by: Lunar
---
 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 46eff1e..afc12b5 100644
--- a/grub-core/lib/syslinux_parse.c
+++ b/grub-core/lib/syslinux_parse.c
@@ -869,7 +869,6 @@ write_entry (struct output_buffer *outbuf,
     case KERNEL_LINUX:
       {
 	char *ptr;
-	char *cmdline;
 	char *initrd = NULL;
 	for (ptr = curentry->append; ptr && *ptr; ptr++)
 	  if ((ptr == curentry->append || grub_isspace (ptr[-1]))
@@ -879,31 +878,19 @@ write_entry (struct output_buffer *outbuf,
 	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)
+	    initrd = grub_strdup(ptr + sizeof ("initrd=") - 1);
+	    if (!initrd)
 	      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 (ptr2 = initrd; *ptr2 && !grub_isspace (*ptr2); ptr2++);
+	    *ptr2 = 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));
+	if (curentry->append)
+	  print (outbuf, curentry->append, grub_strlen (curentry->append));
 	print_string ("\n");
 	if (initrd || curentry->initrds)
 	  {
@@ -922,8 +909,7 @@ write_entry (struct output_buffer *outbuf,
 
 	    print_string ("\n");
 	  }
-	if (ptr && *ptr)
-	  grub_free (cmdline);
+	grub_free (initrd);
       }
       break;
     case KERNEL_CHAINLOADER:
-- 
2.4.3