A couple BLS fixes and various grub2 cleanups

- Various grub2 cleanups (pbrobinson)
- Another fix for blscfg variable expansion support
- blscfg: Add support for sorting the plus ('+') higher than base version
  Resolves: rhbz#1767395

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
This commit is contained in:
Javier Martinez Canillas 2019-12-05 17:03:13 +01:00
parent 8733281382
commit 3f3dfd4006
No known key found for this signature in database
GPG key ID: C751E590D63F3D69
4 changed files with 100 additions and 9 deletions

View file

@ -15,14 +15,27 @@ Resolves: rhbz#1669252
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/commands/blscfg.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
grub-core/commands/blscfg.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index 471975fd2e5..32d3252502e 100644
index 471975fd2e5..d78cff79f97 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -602,17 +602,16 @@ static char *field_append(bool is_var, char *buffer, char *start, char *end)
@@ -593,26 +593,29 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num)
static char *field_append(bool is_var, char *buffer, char *start, char *end)
{
- char *temp = grub_strndup(start, end - start + 1);
- const char *field = temp;
+ char *tmp = grub_strndup(start, end - start + 1);
+ const char *field = tmp;
+ int term = is_var ? 2 : 1;
if (is_var) {
- field = grub_env_get (temp);
+ field = grub_env_get (tmp);
if (!field)
return buffer;
}
@ -35,17 +48,29 @@ index 471975fd2e5..32d3252502e 100644
- if (!buffer)
- return NULL;
+ if (!buffer)
+ buffer = grub_zalloc (grub_strlen(field) + 1);
+ buffer = grub_zalloc (grub_strlen(field) + term);
+ else
+ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + 1);
+ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + term);
- grub_stpcpy (buffer + grub_strlen(buffer), field);
- }
+ if (!buffer)
+ return NULL;
+
+ grub_stpcpy (buffer + grub_strlen(buffer), field);
+ grub_stpcpy (buffer + grub_strlen(buffer), " ");
+ tmp = buffer + grub_strlen(buffer);
+ tmp = grub_stpcpy (tmp, field);
+
+ if (is_var)
+ tmp = grub_stpcpy (tmp, " ");
return buffer;
}
@@ -642,6 +645,8 @@ static char *expand_val(char *value)
buffer = field_append(is_var, buffer, start, end);
is_var = false;
start = value;
+ if (*start == ' ')
+ start++;
}
}

View file

@ -0,0 +1,59 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Mon, 4 Nov 2019 17:33:30 +0100
Subject: [PATCH] blscfg: Add support for sorting the plus ('+') higher than
base version
Handle plus separator. Concept is the same as tilde, except that if one of
the strings ends (base version), the other is considered as higher version.
A plus character is used for example by the Linux kernel build system to
denote that is the base version plus some changes on top of it.
Currently for example rpmvercmp("5.3.0", "5.3.0+") will return 0 even when
the two versions are not the same.
Resolves: rhbz#1767395
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/commands/blscfg.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index d78cff79f97..83b33c1cd93 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -163,8 +163,8 @@ static int vercmp(const char * a, const char * b)
/* loop through each version segment of str1 and str2 and compare them */
while (*one || *two) {
- while (*one && !grub_isalnum(*one) && *one != '~') one++;
- while (*two && !grub_isalnum(*two) && *two != '~') two++;
+ while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+') one++;
+ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+') two++;
/* handle the tilde separator, it sorts before everything else */
if (*one == '~' || *two == '~') {
@@ -175,6 +175,21 @@ static int vercmp(const char * a, const char * b)
continue;
}
+ /*
+ * Handle plus separator. Concept is the same as tilde,
+ * except that if one of the strings ends (base version),
+ * the other is considered as higher version.
+ */
+ if (*one == '+' || *two == '+') {
+ if (!*one) return -1;
+ if (!*two) return 1;
+ if (*one != '+') goto_return (1);
+ if (*two != '+') goto_return (-1);
+ one++;
+ two++;
+ continue;
+ }
+
/* If we ran to the end of either, we are finished with the loop */
if (!(*one && *two)) break;

View file

@ -187,3 +187,4 @@ Patch0186: 0186-grub-set-bootflag-Update-comment-about-running-as-ro.patch
Patch0187: 0187-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch
Patch0188: 0188-blscfg-add-a-space-char-when-appending-fields-for-va.patch
Patch0189: 0189-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch
Patch0190: 0190-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch

View file

@ -9,7 +9,7 @@
Name: grub2
Epoch: 1
Version: 2.04
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+
URL: http://www.gnu.org/software/grub/
@ -513,6 +513,12 @@ rm -r /boot/grub2.tmp/ || :
%endif
%changelog
* Thu Dec 05 2019 Javier Martinez Canillas <javierm@redhat.com> - 2.04-6
- Various grub2 cleanups (pbrobinson)
- Another fix for blscfg variable expansion support
- blscfg: Add support for sorting the plus ('+') higher than base version
Resolves: rhbz#1767395
* Wed Nov 27 2019 Javier Martinez Canillas <javierm@redhat.com> - 2.04-5
- blscfg: add a space char when appending fields for variable expansion
- grub.d: Fix boot_indeterminate getting set on boot_success=0 boot