From 688051cb21d6748bc908009b5c012e0ef93d1ae6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Dec 2018 20:22:40 +0100 Subject: [PATCH 1/2] autoupdater: fix regression in version compare Version strings with the same prefix, e.g. "1.0" and "1.0~pre", or even "1.0" and "1.0.1" were considered equal. This is a regression in the C autoupdater rewrite. --- admin/autoupdater/src/version.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/autoupdater/src/version.c b/admin/autoupdater/src/version.c index dd4d3ff..f1967e7 100644 --- a/admin/autoupdater/src/version.c +++ b/admin/autoupdater/src/version.c @@ -47,7 +47,7 @@ bool newer_than(const char *a, const char *b) { if (b == NULL) return true; - while (*a != '\0' && *b != '\0') { + while (*a != '\0' || *b != '\0') { int first_diff = 0; // compare non-digits character by character From 30be52e03bbfdad738f23700e56ff1c029818eba Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Dec 2018 20:31:43 +0100 Subject: [PATCH 2/2] autoupdater: consider end of string smaller than all characters except for '~' This fixes ordering for the following patterns: * 1.0 < 1.0a * 1.0a < 1.0ab * 1.0a < 1.0a1 Note that trailing zeros are still ignored (1.0 == 1., 1test0 == 1test), which matches the behaviour of dpkg and opkg. --- admin/autoupdater/src/version.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/admin/autoupdater/src/version.c b/admin/autoupdater/src/version.c index f1967e7..6623ad9 100644 --- a/admin/autoupdater/src/version.c +++ b/admin/autoupdater/src/version.c @@ -34,8 +34,10 @@ static int char_order(char c) { return 0; else if (isalpha(c)) return c; - else if (c == '~') + else if (c == '\0') return -1; + else if (c == '~') + return -2; else return c + 256; }