summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-03-04 17:18:09 +0000
committerRichard Hughes <richard@hughsie.com>2015-03-04 17:18:09 +0000
commitd409c9bf898a0baae7ea5d89ef444bfb6f16caa5 (patch)
treeaccaa919fbce82b4f3c74ea75702a743d63be815
parent0f515548fe6bcd2abf9261f215f932d498de714e (diff)
downloadappstream-glib-d409c9bf898a0baae7ea5d89ef444bfb6f16caa5.tar.gz
trivial: Don't accept negative version components
In this case, fall back to using the timestamp.
-rw-r--r--libappstream-glib/as-self-test.c1
-rw-r--r--libappstream-glib/as-utils.c12
2 files changed, 9 insertions, 4 deletions
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index be3e13a..366f4c2 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -3312,6 +3312,7 @@ as_test_utils_vercmp_func (void)
/* non-numeric */
g_assert_cmpint (as_utils_vercmp ("1.2xxx.3", "1.2.3"), ==, G_MAXINT);
g_assert_cmpint (as_utils_vercmp ("1.2a.3", "1.2b.3"), ==, G_MAXINT);
+ g_assert_cmpint (as_utils_vercmp ("1.2.-3", "1.2.3"), ==, G_MAXINT);
/* invalid */
g_assert_cmpint (as_utils_vercmp ("1", NULL), ==, G_MAXINT);
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index c8289db..52f48f4 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -1646,8 +1646,8 @@ gint
as_utils_vercmp (const gchar *version_a, const gchar *version_b)
{
gchar *endptr;
- guint64 ver_a;
- guint64 ver_b;
+ gint64 ver_a;
+ gint64 ver_b;
guint i;
guint longest_split;
_cleanup_strv_free_ gchar **split_a = NULL;
@@ -1674,12 +1674,16 @@ as_utils_vercmp (const gchar *version_a, const gchar *version_b)
return 1;
/* compare integers */
- ver_a = g_ascii_strtoull (split_a[i], &endptr, 10);
+ ver_a = g_ascii_strtoll (split_a[i], &endptr, 10);
if (endptr != NULL && endptr[0] != '\0')
return G_MAXINT;
- ver_b = g_ascii_strtoull (split_b[i], &endptr, 10);
+ if (ver_a < 0)
+ return G_MAXINT;
+ ver_b = g_ascii_strtoll (split_b[i], &endptr, 10);
if (endptr != NULL && endptr[0] != '\0')
return G_MAXINT;
+ if (ver_b < 0)
+ return G_MAXINT;
if (ver_a < ver_b)
return -1;
if (ver_a > ver_b)