fix: nemo-window-manage-views: fix use-after-free crash in desktop sl…#3781
Conversation
…ot callback nemo_file_call_when_ready() was called with a raw NemoWindowSlot * as callback_data. If the slot was destroyed between registration and idle dispatch, the callback received a dangling pointer and crashed immediately on the g_assert(NEMO_IS_WINDOW_SLOT(slot)) inside nemo_window_slot_get_window(). Crash trace: SIGABRT ← g_assert failure nemo_window_slot_get_window() nemo-window-slot.c:528 got_file_info_for_view_selection_callback() nemo-window-manage-views.c:822 desktop_callback_check_done() nemo-desktop-directory-file.c:241 call_ready_callbacks_at_idle() nemo-directory-async.c:1850 Fix: use a GObject weak reference (Solution B). Introduce SlotWeakData, a small heap-allocated sentinel that holds the slot pointer and is registered as a GWeakNotify on the slot. When GObject finalizes the slot, slot_weak_notify() zeroes wd->slot. The callback checks this field at entry and returns safely if the slot is gone. Add slot->determine_view_weak_data to NemoWindowSlot so that free_location_change() can retrieve the correct SlotWeakData pointer, pass it to nemo_file_cancel_call_when_ready() (which matches on both callback and callback_data), remove the weak ref, and free the sentinel without leaving dangling notifiers. The same guard is applied to all three call-sites that register got_file_info_for_view_selection_callback: - begin_location_change() - mount_not_mounted_callback() - the parent-redirect branch inside the callback itself Files changed: src/nemo-window-slot.h add determine_view_weak_data field src/nemo-window-manage-views.c implement weak-ref guard
|
Note: this PR appears to be associated with an un-supervised or minimally-supervised long-running autonomous agentic AI system run against Fedora bugs by a Fedora contributor. This system has produced incorrect diagnoses and fixes in multiple cases. See https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/SFVETHOYKQAO7KKLEXCK4IBT4WVPRE6F/ . The downstream report that triggered this PR is https://bugzilla.redhat.com/show_bug.cgi?id=2481175 , the traceback is available there. I'm not enough of a C coder to say whether this fix is correct and will address the bug, but please review it with caution given the track record of this system. |
|
Further update: the Fedora contributor, or another party or AI system with access to their email address, has now asserted that their credentials were compromised and an unknown third party was operating the presumed autonomous AI system that generated this PR. Again, please treat it with caution. |
Summary
Fixes a
SIGABRTcrash innemo-desktopcaused by a use-after-free (dangling pointer) onNemoWindowSlotinside an async GLib file-info callback.Fixes: linuxmint/nemo#XXXX (update with actual issue number)
Problem
nemo-desktopcrashed with the following assertion failure:Signal:
SIGABRTCrashed process:
/usr/bin/nemo-desktopRoot cause
The crash originates in
got_file_info_for_view_selection_callback()insrc/nemo-window-manage-views.c.When a directory change is initiated,
begin_location_change()callsnemo_file_call_when_ready(), passing the rawNemoWindowSlot *pointer ascallback_data. GLib schedules the callback to fire at idle time(
g_idle_add). If theNemoWindowSlotis destroyed between registrationand dispatch (e.g. the desktop window is torn down during startup), the
pointer becomes a dangling reference. When the idle callback eventually fires,
the first thing it does is call
nemo_window_slot_get_window(slot), whichhits the internal
g_assert (NEMO_IS_WINDOW_SLOT (slot))— and aborts.Relevant stack frames (from coredump)
Solution
Applied GObject weak reference guard (Solution B):
Instead of passing the raw
NemoWindowSlot *directly ascallback_data, wenow allocate a small heap-resident sentinel struct (
SlotWeakData) that holdsthe slot pointer and is registered as a
GWeakNotifyon the slot object.When GObject finalizes the slot, it calls
slot_weak_notify(), which zeroeswd->slot. When the callback eventually fires, it checks whetherwd->slotis still valid before touching the slot — and returns safely if not.
If
free_location_change()cancels a pending call before it fires, itcorrectly retrieves the saved
SlotWeakData *from the newslot->determine_view_weak_datafield, passes it ascallback_datatonemo_file_cancel_call_when_ready()(which matches on both callback pointerand data pointer), removes the weak ref, and frees the sentinel — leaving no
dangling notifiers.
Show: https://bugzilla.redhat.com/show_bug.cgi?id=2481175