From 4f589b39bdf752c92aceb78efd9c356619d67207 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 11 Sep 2009 14:54:22 -0400
Subject: [PATCH 1/2] Allow tmplLine to be NULL in getInitrdVal

getInitrdVal is sometimes called when no template is
available.  In those cases, we shouldn't crash.
---
 grubby.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/grubby.c b/grubby.c
index 12b7a41..6aaedb5 100644
--- a/grubby.c
+++ b/grubby.c
@@ -2388,10 +2388,12 @@ static char * getInitrdVal(struct grubConfig * config,
 
 	extraInitrd = extraInitrds[i] + prefixLen;
 	/* Don't add entries that are already there */
-	for (j = 2; j < tmplLine->numElements; j++)
-		if (strcmp(extraInitrd, tmplLine->elements[j].item) == 0) break;
+	if (tmplLine != NULL) {
+	    for (j = 2; j < tmplLine->numElements; j++)
+		    if (strcmp(extraInitrd, tmplLine->elements[j].item) == 0) break;
 
-	if (j != tmplLine->numElements) continue;
+	    if (j != tmplLine->numElements) continue;
+	}
 
 	*end++ = separatorChar;
 	end = stpcpy(end, extraInitrd);
@@ -2693,7 +2695,7 @@ int addNewKernel(struct grubConfig * config, struct singleEntry * template,
     }
     if (needs & NEED_INITRD) {
 	char *initrdVal;
-	initrdVal = getInitrdVal(config, prefix, tmplLine, newKernelInitrd, extraInitrds, extraInitrdCount);
+	initrdVal = getInitrdVal(config, prefix, NULL, newKernelInitrd, extraInitrds, extraInitrdCount);
 	newLine = addLine(new, config->cfi,
 			  (new->multiboot && getKeywordByType(LT_MBMODULE,
 							      config->cfi)) ?
-- 
1.6.4.2


From f57f33e7219ed05e758e43b6778328675e2f694f Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 11 Sep 2009 14:56:11 -0400
Subject: [PATCH 2/2] Add a couple of test cases for extra initrds

While we don't have full coverage of the feature yet,
these two tests are a start.
---
 test.sh               |    4 ++++
 test/results/add/g1.5 |   19 +++++++++++++++++++
 test/results/add/g1.6 |   19 +++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
 create mode 100644 test/results/add/g1.5
 create mode 100644 test/results/add/g1.6

diff --git a/test.sh b/test.sh
index 3a52bfe..eee3ae4 100755
--- a/test.sh
+++ b/test.sh
@@ -282,6 +282,10 @@ grubTest grub.1 add/g1.3 --add-kernel=/boot/new-kernel.img --title='title' \
     --initrd=/boot/new-initrd --boot-filesystem=/ --copy-default
 grubTest grub.1 add/g1.4 --add-kernel=/boot/new-kernel.img --title='title' \
     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default
+grubTest grub.1 add/g1.5 --add-kernel=/boot/new-kernel.img --title='title' \
+    --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/
+grubTest grub.1 add/g1.6 --add-kernel=/boot/new-kernel.img --title='title' \
+    --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/boot
 grubTest grub.2 add/g2.1 --add-kernel=/boot/vmlinuz-2.4.7-2	    \
     --initrd=/boot/initrd-2.4.7-new.img --boot-filesystem=/boot --copy-default \
     --title="Red Hat Linux (2.4.7-2)"					    \
diff --git a/test/results/add/g1.5 b/test/results/add/g1.5
new file mode 100644
index 0000000..6301338
--- /dev/null
+++ b/test/results/add/g1.5
@@ -0,0 +1,19 @@
+# grub.conf generated by anaconda
+#
+# Note that you do not have to rerun grub after making changes to this file
+# NOTICE:  You have a /boot partition.  This means that
+#          all kernel and initrd paths are relative to /boot/, eg.
+#          root (hd0,0)
+#          kernel /vmlinuz-version ro root=/dev/sda1
+#          initrd /initrd-version.img
+#boot=/dev/hda
+default=1
+timeout=10
+splashimage=(hd0,0)/grub/splash.xpm.gz
+title title
+	kernel /boot/new-kernel.img
+	initrd /boot/new-initrd /boot/extra-initrd
+title Red Hat Linux (2.4.7-2)
+	root (hd0,0)
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
+	initrd /initrd-2.4.7-2.img
diff --git a/test/results/add/g1.6 b/test/results/add/g1.6
new file mode 100644
index 0000000..69189f5
--- /dev/null
+++ b/test/results/add/g1.6
@@ -0,0 +1,19 @@
+# grub.conf generated by anaconda
+#
+# Note that you do not have to rerun grub after making changes to this file
+# NOTICE:  You have a /boot partition.  This means that
+#          all kernel and initrd paths are relative to /boot/, eg.
+#          root (hd0,0)
+#          kernel /vmlinuz-version ro root=/dev/sda1
+#          initrd /initrd-version.img
+#boot=/dev/hda
+default=1
+timeout=10
+splashimage=(hd0,0)/grub/splash.xpm.gz
+title title
+	kernel /new-kernel.img
+	initrd /new-initrd /extra-initrd
+title Red Hat Linux (2.4.7-2)
+	root (hd0,0)
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
+	initrd /initrd-2.4.7-2.img
-- 
1.6.4.2

