Skip to content

Commit 7288e9a

Browse files
author
smpl-os
committed
libnemo-private: fix use-after-free crash in nemo_file_mark_gone
nemo_directory_remove_file() calls nemo_file_unref() when the directory is monitoring its file list. If the caller holds no extra ref, this can drop the refcount to zero and free the NemoFile object. The nemo_file_clear_info() call immediately after then dereferences the freed pointer, causing a SIGSEGV. Fix: take a temporary ref before the if-block so the object stays alive through both nemo_directory_remove_file() and nemo_file_clear_info(), and release it only after both calls complete. Closes #3712
1 parent 58846d5 commit 7288e9a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libnemo-private/nemo-file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7947,11 +7947,18 @@ nemo_file_mark_gone (NemoFile *file)
79477947

79487948
/* Let the directory know it's gone. */
79497949
directory = file->details->directory;
7950+
/* Hold a temporary ref so the object stays alive through both
7951+
* nemo_directory_remove_file() (which may drop the last directory ref
7952+
* and free the object) AND the nemo_file_clear_info() call below.
7953+
* Without this, remove_file can free the NemoFile and clear_info then
7954+
* dereferences the freed pointer, causing a SIGSEGV (bug #3712). */
7955+
nemo_file_ref (file);
79507956
if (!nemo_file_is_self_owned (file)) {
79517957
nemo_directory_remove_file (directory, file);
79527958
}
79537959

79547960
nemo_file_clear_info (file);
7961+
nemo_file_unref (file);
79557962

79567963
/* FIXME bugzilla.gnome.org 42429:
79577964
* Maybe we can get rid of the name too eventually, but

0 commit comments

Comments
 (0)