From c50118863f81bb039d19f60c9d844051e1442cda Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 2 Sep 2019 18:02:05 +0100 Subject: 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 --- src/xdgmimecache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3