From 488beeb623bba0a470f8eafe30e7cf492bb94e81 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 6 Feb 2018 22:02:53 +0100 Subject: [PATCH 1/1] Crash in thunar_file_is_gfile_ancestor (bug #14202) --- thunar/thunar-file.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 46d0dc72..f70e5ada 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2809,25 +2809,31 @@ gboolean thunar_file_is_gfile_ancestor (const ThunarFile *file, GFile *ancestor) { - gboolean is_ancestor = FALSE; GFile *current = NULL; GFile *tmp; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + _thunar_return_val_if_fail (G_IS_FILE (file->gfile), FALSE); _thunar_return_val_if_fail (G_IS_FILE (ancestor), FALSE); - for (current = g_object_ref (file->gfile); - is_ancestor == FALSE && current != NULL; - tmp = g_file_get_parent (current), g_object_unref (current), current = tmp) + current = g_object_ref (file->gfile); + while(TRUE) { + tmp = g_file_get_parent (current); + g_object_unref (current); + current = tmp; + + if (current == NULL) /* parent of root is NULL */ + return FALSE; + if (G_UNLIKELY (g_file_equal (current, ancestor))) - is_ancestor = TRUE; + { + g_object_unref (current); + return TRUE; + } } - if (current != NULL) - g_object_unref (current); - - return is_ancestor; + return FALSE; } -- 2.11.0