summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-09-12 12:40:20 +0100
committerRichard Hughes <richard@hughsie.com>2014-09-12 13:04:04 +0100
commite79bd6f928eb54fbd02777b553d891160e7745d6 (patch)
treecf99af352676abc2e7256865f68931259d5132bd
parent842f8715e5166503c2c641e9567a40522caa951d (diff)
downloadappstream-glib-e79bd6f928eb54fbd02777b553d891160e7745d6.tar.gz
Do not crash when doing as_tag_from_string(NULL)
-rw-r--r--libappstream-glib/as-self-test.c1
-rw-r--r--libappstream-glib/as-tag.c4
2 files changed, 5 insertions, 0 deletions
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 1a526c9..6feebb2 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -64,6 +64,7 @@ as_test_tag_func (void)
g_assert_cmpstr (as_tag_to_string (AS_TAG_UNKNOWN), ==, "unknown");
g_assert_cmpint (as_tag_from_string ("url"), ==, AS_TAG_URL);
g_assert_cmpint (as_tag_from_string ("xxx"), ==, AS_TAG_UNKNOWN);
+ g_assert_cmpint (as_tag_from_string (NULL), ==, AS_TAG_UNKNOWN);
/* deprecated names */
g_assert_cmpint (as_tag_from_string_full ("appcategories",
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index 46fcaa4..0ca5257 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -79,6 +79,10 @@ as_tag_from_string_full (const gchar *tag, AsTagFlags flags)
#endif
AsTag etag = AS_TAG_UNKNOWN;
+ /* invalid */
+ if (tag == NULL)
+ return AS_TAG_UNKNOWN;
+
#ifdef HAVE_GPERF
/* use a perfect hash */
ky = as_tag_from_gperf (tag, strlen (tag));