Skip to contentSkip to conversation

Behavior of syslinux_parse differs from SYSLINUX for initrd= option

bug #44239 Lunar 2 participants 2 messages Feb 13, 2015 – Feb 16, 2015 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Lunar

author
#2 lore raw

Andrei Borzenkov:

Quoted 9 lines

Follow-up Comment #1, bug #44239 (project grub):

Can't comment about behavior itself. Re. patch

(quoted diff) +1 -0
+	cmdline = grub_strdup(curentry->append);

Error check missing.

(quoted diff) +1 -0
+	grub_free(cmdline);

You need to delete free(cmdline) later.

Both fixed.

Quoted 1 line

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

Here it is.

Signature · 1 line
Lunar                                             <[email protected]>

From d1a88855eea4b2b3099d8ad8ff689305f74736cd Mon Sep 17 00:00:00 2001
From: Lunar <[email protected]>
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(-)
grub-core/lib/syslinux_parse.c +7 -21
index b0d5f9e..1318c3a 100644
@@ -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:
Signature · 1 line
1.9.1
#3 lore raw
Quoted 8 lines · Lunar

Andrei Borzenkov:

Quoted 7 lines

Follow-up Comment #1, bug #44239 (project grub):

Can't comment about behavior itself. Re. patch

(quoted diff) +1 -0
+	cmdline = grub_strdup(curentry->append);

Error check missing.

Quoted 9 lines
Quoted 2 lines
(quoted diff) +1 -0
+	grub_free(cmdline);

You need to delete free(cmdline) later.

Both fixed.

Quoted 1 line

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

Here it is.

The code at this place turned out to be not very understandable. I simplified the code and did the change you requested.

Quoted 7 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel