Blob Blame History Raw
From 628474b5b3a82e779447e296c3e019fe913800ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Tue, 23 Jan 2018 14:32:25 +0100
Subject: [PATCH 1/2] as-app-desktop: don't deference invalid lists

Malformed .desktop files might causes crashes when
returned lists are NULL.
---
 libappstream-glib/as-app-desktop.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libappstream-glib/as-app-desktop.c b/libappstream-glib/as-app-desktop.c
index 1f12683..fadf4ab 100644
--- a/libappstream-glib/as-app-desktop.c
+++ b/libappstream-glib/as-app-desktop.c
@@ -236,7 +236,7 @@ as_app_parse_file_key (AsApp *app,
 						   G_KEY_FILE_DESKTOP_GROUP,
 						   key,
 						   NULL, NULL);
-		for (i = 0; list[i] != NULL; i++) {
+		for (i = 0; list != NULL && list[i] != NULL; i++) {
 			const gchar *category_blacklist[] = {
 				"X-GNOME-Settings-Panel",
 				"X-Unity-Settings-Panel",
@@ -271,7 +271,7 @@ as_app_parse_file_key (AsApp *app,
 						   G_KEY_FILE_DESKTOP_GROUP,
 						   key,
 						   NULL, NULL);
-		for (i = 0; list[i] != NULL; i++) {
+		for (i = 0; list != NULL && list[i] != NULL; i++) {
 			g_auto(GStrv) kw_split = NULL;
 			kw_split = g_strsplit (list[i], ",", -1);
 			for (j = 0; kw_split[j] != NULL; j++) {
@@ -291,7 +291,7 @@ as_app_parse_file_key (AsApp *app,
 							  key,
 							  locale,
 							  NULL, NULL);
-		for (i = 0; list[i] != NULL; i++) {
+		for (i = 0; list != NULL && list[i] != NULL; i++) {
 			g_auto(GStrv) kw_split = NULL;
 			kw_split = g_strsplit (list[i], ",", -1);
 			for (j = 0; kw_split[j] != NULL; j++) {
@@ -306,7 +306,7 @@ as_app_parse_file_key (AsApp *app,
 						   G_KEY_FILE_DESKTOP_GROUP,
 						   key,
 						   NULL, NULL);
-		for (i = 0; list[i] != NULL; i++)
+		for (i = 0; list != NULL && list[i] != NULL; i++)
 			as_app_add_mimetype (app, list[i]);
 
 	} else if (g_strcmp0 (key, "X-AppInstall-Package") == 0) {
-- 
2.14.3