From a056ddc904b8540a3e8d1abbb4ae1de6950a6971 Mon Sep 17 00:00:00 2001 From: Ernestas Kulik Date: Tue, 13 Mar 2018 16:00:19 +0100 Subject: file: guard against recursive links when emitting change signals Currently, when propagating file changes, the code recursively notifies the files that link to the original file. This quickly falls apart with recursive links, as a stack overflow occurs. The fix is only partial, however, in that if you try a bit harder, you can still crash Nautilus by throwing in another file into the loop (hah). Fixes https://gitlab.gnome.org/GNOME/nautilus/issues/289 --- src/nautilus-file.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nautilus-file.c b/src/nautilus-file.c index 37f189f8c..5865c3229 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -8581,10 +8581,29 @@ nautilus_file_emit_changed (NautilusFile *file) link_files = get_link_files (file); for (p = link_files; p != NULL; p = p->next) { - if (p->data != file) + /* Looking for directly recursive links. */ + g_autolist (NautilusFile) link_targets = NULL; + NautilusDirectory *directory; + + if (p->data == file) + { + continue; + } + + link_targets = get_link_files (p->data); + directory = nautilus_file_get_directory (p->data); + + /* Reiterating (heh) that this will break with more complex cycles. + * Users, stop trying to break things on purpose. + */ + if (g_list_find (link_targets, file) != NULL && + directory == nautilus_file_get_directory (file)) { - nautilus_file_changed (NAUTILUS_FILE (p->data)); + g_signal_emit (p->data, signals[CHANGED], 0, p->data); + continue; } + + nautilus_file_changed (NAUTILUS_FILE (p->data)); } nautilus_file_list_free (link_files); } -- cgit v1.2.1