summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2019-09-02 18:02:05 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-06-17 12:03:54 +0100
commitc50118863f81bb039d19f60c9d844051e1442cda (patch)
tree5b95f27b27c1283d389e3a69da252ad898877409
parent462198f8972bb9ce73b38942422d25ac9fd3c142 (diff)
xdgmime: Prevent infinite loops from badly-formed MIME registrations
Prevent recursion of `_xdg_mime_cache_mime_type_subclass()` with the same value of argument `mime` for the subclasses of a MIME type. This was observed in GLib as https://gitlab.gnome.org/GNOME/glib/-/issues/1875, and a backtrace of the infinite loop is here: https://gitlab.gnome.org/GNOME/glib/-/issues/1875#note_592829. Signed-off-by: Philip Withnall <withnall@endlessm.com>
-rw-r--r--src/xdgmimecache.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c
index 34a520e..213027d 100644
--- a/src/xdgmimecache.c
+++ b/src/xdgmimecache.c
@@ -893,7 +893,9 @@ _xdg_mime_cache_mime_type_subclass (const char *mime,
for (j = 0; j < n_parents; j++)
{
parent_offset = GET_UINT32 (cache->buffer, offset + 4 + 4 * j);
- if (_xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
+ if (strcmp (cache->buffer + parent_offset, mime) != 0 &&
+ strcmp (cache->buffer + parent_offset, umime) != 0 &&
+ _xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
return 1;
}