gicmo / rpms / grub2

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