grubby/Fix-incorrect-test-case-and-remove-args-with-a-value.patch
2019-12-30 14:36:43 +08:00

171 lines
5.0 KiB
Diff

From 46cab02a27010d74144a6342efc2b34961bb2e69 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 27 Sep 2017 11:28:00 -0400
Subject: [PATCH 45/60] Fix incorrect test case and --remove-args with a
value.
Currently we have this test case:
grubTest grub.3 updargs/g3.4 --update-kernel=ALL
--remove-args="hdd=foobar"
This fails to notice that the actual argument in grub.3 is hdd=ide-scsi,
and removes it anyway, and the data in g3.4 supports that behavior.
This is clearly wrong, and so this patch introduces updargs/g3.5, which
leaves hdd=ide-scsi intact, and fixes the code so that it won't modify
the command line in that case.
Resolves: rhbz#1476273
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grubby.c | 73 ++++++++++++++++++++++++++++++++++++++++-------
test.sh | 2 +-
test/results/updargs/g3.5 | 16 +++++++++++
3 files changed, 79 insertions(+), 12 deletions(-)
create mode 100644 test/results/updargs/g3.5
diff --git a/grubby.c b/grubby.c
index 951abb7..c2fab23 100644
--- a/grubby.c
+++ b/grubby.c
@@ -3270,20 +3270,68 @@ static void removeElement(struct singleLine * line, int removeHere) {
line->numElements--;
}
-int argMatch(const char * one, const char * two) {
+static int argNameMatch(const char *one, const char *two)
+{
char * first, * second;
- char * chptr;
+ char *chptra, *chptrb;
+ int rc;
first = strcpy(alloca(strlen(one) + 1), one);
second = strcpy(alloca(strlen(two) + 1), two);
- chptr = strchr(first, '=');
- if (chptr) *chptr = '\0';
+ chptra = strchr(first, '=');
+ if (chptra)
+ *chptra = '\0';
+
+ chptrb = strchr(second, '=');
+ if (chptrb)
+ *chptrb = '\0';
+
+ rc = strcmp(first, second);
+
+ if (chptra)
+ *chptra = '=';
+ if (chptrb)
+ *chptrb = '=';
+
+ return rc;
+}
+
+static int argHasValue(const char *arg)
+{
+ char *chptr;
+
+ chptr = strchr(arg, '=');
- chptr = strchr(second, '=');
- if (chptr) *chptr = '\0';
+ if (chptr)
+ return 1;
+ return 0;
+}
- return strcmp(first, second);
+static int argValueMatch(const char *one, const char *two)
+{
+ char *first, *second;
+ char *chptra, *chptrb;
+
+ first = strcpy(alloca(strlen(one) + 1), one);
+ second = strcpy(alloca(strlen(two) + 1), two);
+
+ chptra = strchr(first, '=');
+ if (chptra)
+ chptra += 1;
+
+ chptrb = strchr(second, '=');
+ if (chptrb)
+ chptrb += 1;
+
+ if (!chptra && !chptrb)
+ return 0;
+ else if (!chptra)
+ return *chptrb - 0;
+ else if (!chptrb)
+ return 0 - *chptra;
+ else
+ return strcmp(chptra, chptrb);
}
int updateActualImage(struct grubConfig * cfg, const char * image,
@@ -3419,7 +3467,7 @@ int updateActualImage(struct grubConfig * cfg, const char * image,
}
if (usedElements[i])
continue;
- if (!argMatch(line->elements[i].item, *arg)) {
+ if (!argNameMatch(line->elements[i].item, *arg)) {
usedElements[i]=1;
break;
}
@@ -3470,9 +3518,12 @@ int updateActualImage(struct grubConfig * cfg, const char * image,
!strcmp(line->elements[i].item, "--"))
/* reached the end of hyper args, stop here */
break;
- if (!argMatch(line->elements[i].item, *arg)) {
- removeElement(line, i);
- break;
+ if (!argNameMatch(line->elements[i].item, *arg)) {
+ if (!argHasValue(*arg) ||
+ !argValueMatch(line->elements[i].item, *arg)) {
+ removeElement(line, i);
+ break;
+ }
}
}
/* handle removing LT_ROOT line too */
diff --git a/test.sh b/test.sh
index a6da290..5d59216 100755
--- a/test.sh
+++ b/test.sh
@@ -381,7 +381,7 @@ grubTest grub.3 updargs/g3.2 --update-kernel=DEFAULT \
--args "root=/dev/hdd1 hdd=notide-scsi"
grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd"
grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd=ide-scsi"
-grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd=foobar"
+grubTest grub.3 updargs/g3.5 --update-kernel=ALL --remove-args="hdd=foobar"
grubTest grub.3 updargs/g3.7 --update-kernel=ALL \
--remove-args="hdd root ro"
grubTest grub.7 updargs/g7.2 --boot-filesystem=/ \
diff --git a/test/results/updargs/g3.5 b/test/results/updargs/g3.5
new file mode 100644
index 0000000..7d50bb8
--- /dev/null
+++ b/test/results/updargs/g3.5
@@ -0,0 +1,16 @@
+#boot=/dev/hda
+timeout=10
+splashimage=(hd0,1)/grub/splash.xpm.gz
+title Red Hat Linux (2.4.7-2smp)
+ root (hd0,1)
+ kernel /vmlinuz-2.4.7-2smp ro root=/dev/hda5 hdd=ide-scsi
+ initrd /initrd-2.4.7-2smp.img
+title Red Hat Linux-up (2.4.7-2)
+ root (hd0,1)
+ kernel /vmlinuz-2.4.7-2 ro root=/dev/hda5 hdd=ide-scsi
+ initrd /initrd-2.4.7-2.img
+title DOS
+ rootnoverify (hd0,0)
+ chainloader +1
+
+
--
2.19.1