diff options
author | Richard Hughes <richard@hughsie.com> | 2018-03-12 14:48:35 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2018-03-12 14:49:58 +0000 |
commit | ca2af388bee741e53ca7410733bcdbd968fe37c5 (patch) | |
tree | c3d536e81eefc41e6eec7778ad9876841aecbeac | |
parent | 9dd1c46d46b881cfb930cf7023d3625ff7fd0745 (diff) | |
download | colord-ca2af388bee741e53ca7410733bcdbd968fe37c5.tar.gz |
Fix crash when parsing an invalid country code
If we return with NULL, we have to set an error...
-rw-r--r-- | lib/colord/cd-icc.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/colord/cd-icc.c b/lib/colord/cd-icc.c index e5f436a..f231814 100644 --- a/lib/colord/cd-icc.c +++ b/lib/colord/cd-icc.c @@ -1280,22 +1280,42 @@ cd_util_mlu_object_parse (const gchar *locale, } /* ignore ##@latin */ - if (g_strstr_len (locale, -1, "@") != NULL) + if (g_strstr_len (locale, -1, "@") != NULL) { + g_set_error (error, + CD_ICC_ERROR, + CD_PROFILE_ERROR_FAILED_TO_PARSE, + "ignoring @latin"); return NULL; + } key = g_strdup (locale); g_strdelimit (key, ".", '\0'); split = g_strsplit (key, "_", -1); - if (strlen (split[0]) != 2) + if (strlen (split[0]) != 2) { + g_set_error (error, + CD_ICC_ERROR, + CD_PROFILE_ERROR_FAILED_TO_PARSE, + "ignoring invalid country code: %s", split[0]); return NULL; + } type = g_strv_length (split); - if (type > 2) + if (type > 2) { + g_set_error (error, + CD_ICC_ERROR, + CD_PROFILE_ERROR_FAILED_TO_PARSE, + "ignoring invalid locale: %s", key); return NULL; + } /* convert to wchars */ wtext = g_utf8_to_ucs4 (utf8_text, -1, NULL, NULL, error); - if (wtext == NULL) + if (wtext == NULL) { + g_set_error (error, + CD_ICC_ERROR, + CD_PROFILE_ERROR_FAILED_TO_PARSE, + "ignoring invalid UTF-8 text: %s", utf8_text); return NULL; + } /* lv */ if (type == 1) { @@ -1306,8 +1326,13 @@ cd_util_mlu_object_parse (const gchar *locale, } /* en_GB */ - if (strlen (split[1]) != 2) + if (strlen (split[1]) != 2) { + g_set_error (error, + CD_ICC_ERROR, + CD_PROFILE_ERROR_FAILED_TO_PARSE, + "ignoring invalid locale: %s", split[1]); return NULL; + } obj = g_new0 (CdMluObject, 1); obj->language_code = g_strdup (split[0]); obj->country_code = g_strdup (split[1]); |