From 0a64fa43f79828b36f3a060c7e0d4506b39ae394 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Sat, 30 Jun 2018 18:09:54 -0500 Subject: [PATCH 4/6] Fix buffer underflow in __gio_xdg_cache_mime_type_subclass This upstreams the fix from https://gitlab.gnome.org/GNOME/glib/commit/be7f40185fb2ce884112c1f8a4b196ea65350466 https://bugs.freedesktop.org/show_bug.cgi?id=100733 --- src/xdgmime.c | 19 ++++++++++++++----- src/xdgmimecache.c | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/xdgmime.c b/src/xdgmime.c index 815ffea..e5669c0 100644 --- a/src/xdgmime.c +++ b/src/xdgmime.c @@ -741,19 +741,28 @@ xdg_mime_media_type_equal (const char *mime_a, #if 1 static int -xdg_mime_is_super_type (const char *mime) +ends_with (const char *str, + const char *suffix) { int length; - const char *type; + int suffix_length; - length = strlen (mime); - type = &(mime[length - 2]); + length = strlen (str); + suffix_length = strlen (suffix); + if (length < suffix_length) + return 0; - if (strcmp (type, "/*") == 0) + if (strcmp (str + length - suffix_length, suffix) == 0) return 1; return 0; } + +static int +xdg_mime_is_super_type (const char *mime) +{ + return ends_with (mime, "/*"); +} #endif int diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c index 40ad46f..e614025 100644 --- a/src/xdgmimecache.c +++ b/src/xdgmimecache.c @@ -814,19 +814,28 @@ _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name, #if 1 static int -is_super_type (const char *mime) +ends_with (const char *str, + const char *suffix) { int length; - const char *type; + int suffix_length; - length = strlen (mime); - type = &(mime[length - 2]); + length = strlen (str); + suffix_length = strlen (suffix); + if (length < suffix_length) + return 0; - if (strcmp (type, "/*") == 0) + if (strcmp (str + length - suffix_length, suffix) == 0) return 1; return 0; } + +static int +is_super_type (const char *mime) +{ + return ends_with (mime, "/*"); +} #endif int -- 2.17.1