Skip to content

nemo-ui-utilities.c: Fix double free in nemo_make_action_uuid_for_path() - #3905

Open
Mirilindo wants to merge 1 commit into
linuxmint:masterfrom
Mirilindo:fix-action-uuid-double-free
Open

Mirilindo wants to merge 1 commit into
linuxmint:masterfrom
Mirilindo:fix-action-uuid-double-free

Conversation

@Mirilindo

Copy link
Copy Markdown

Hi,

I was looking at how to give a custom action a keyboard shortcut, and found that it goes through ~/.config/nemo/actions-tree.json. While trying a few layouts by hand, I noticed that Nemo crashes on startup when an action entry has a uuid that doesn't end in .nemo_action. That includes the sample@untracked form shown in action-layout-editor/actions-tree.md:

free(): double free detected in tcache 2

If I read the code correctly, nemo_make_action_uuid_for_path() returns copy in that case, but copy is declared g_autofree, so the string is freed on return. The caller, parse_item(), keeps the result in a g_autofree lookup_uuid and would then free it a second time. With a .nemo_action suffix the function returns a new string from g_strndup(), which would explain why layouts saved by the layout editor don't hit this, since it seems to use the file name with its extension.

This PR changes that one line to return g_steal_pointer (&copy);.

How to reproduce:

mkdir -p ~/.local/share/nemo/actions
printf '[Nemo Action]\nName=Sample\nExec=true\nSelection=any\nExtensions=any;\n' > ~/.local/share/nemo/actions/sample.nemo_action
echo '{"toplevel":[{"uuid":"sample@untracked","type":"action"}]}' > ~/.config/nemo/actions-tree.json
nemo -q; nemo

(This replaces any existing actions-tree.json.)

How I tested it: on one machine (CachyOS, Hyprland), with the Nemo 6.8.4 package from my distribution and a local debug build of master (bf7e43f6). To build it here I had to skip the GObject introspection step, because g-ir-scanner isn't installed. That change is not part of this PR. Each run used its own D-Bus session and temporary XDG_CONFIG_HOME / XDG_DATA_HOME, so my real config wasn't involved. I started Nemo 3 times per layout and counted it as fine when it was still running after 5 seconds:

actions-tree.json 6.8.4 master master + this PR
no file ok ok ok
uuid with .nemo_action ok ok ok
uuid without suffix crash crash ok
uuid like test-b@untracked crash crash ok
unknown uuid with .nemo_action ok ok ok
submenu only ok ok ok

On master without the change, gdb shows the second free here (trimmed):

#6  g_autoptr_cleanup_generic_gfree () at glib-autocleanups.h:32
#7  parse_item () at ../libnemo-private/nemo-action-manager.c:703
#8  parse_level () at ../libnemo-private/nemo-action-manager.c:810
#9  iter_actions () at ../libnemo-private/nemo-action-manager.c:836
#10 nemo_action_manager_iterate_actions () at ../libnemo-private/nemo-action-manager.c
#11 rebuild_menu () at ../src/nemo-places-sidebar.c:3891

meson test gives the same results with and without the change in my environment: 2 tests pass, and Copy test fails while Search Engine test and Directory Async test time out, which I think comes from my setup rather than from Nemo.

What I didn't test: the shortcuts themselves, or the layout editor. I only checked that Nemo starts.

A related note on the docs: with this fix, the debug log shows that a uuid without the suffix (test-b) is now found and added to the menu, but the @untracked form is reported as Missing action ... ignored. Reading actions-tree.md next to the code, a few things also don't seem to match any more: it gives the path ~/.config/nemo/actions/actions-tree.json while the code reads ~/.config/nemo/actions-tree.json, the editor seems to write the file name with its .nemo_action extension as the uuid, and the accelerator key isn't mentioned. I'd be happy to send a separate PR for that if it's useful, or to leave it if you'd rather handle it.

If I misread something here, I'd be glad to know, and I'm fine with closing this.

🤖 Generated with Claude Code

I found this while looking at how keyboard shortcuts for actions are
stored in ~/.config/nemo/actions-tree.json. If I read the code
correctly, when the basename doesn't end in ".nemo_action", the
function returns copy, which is declared g_autofree, so the string is
freed on return. The caller, parse_item() in nemo-action-manager.c,
keeps the result in a g_autofree lookup_uuid and would then free it a
second time.

In my tests, an "action" entry whose uuid has no ".nemo_action" suffix
makes Nemo abort on startup with "free(): double free detected in
tcache 2". That includes the "sample@untracked" form shown in
action-layout-editor/actions-tree.md. I saw it with Nemo 6.8.4 from my
distribution and with a local build of master, and gdb points at the
g_autofree cleanup of lookup_uuid in parse_item().

Returning g_steal_pointer (&copy) seems to be enough: with this change,
the same layouts no longer crash in my build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant