Guard seat_get_focus() NULL dereferences#219
Guard seat_get_focus() NULL dereferences#219hack-heart wants to merge 1 commit intodawsers:masterfrom
Conversation
|
Thank you for taking the time to do this. I added one comment about content, and another about how to go about this, in the sense that the first three cases are in "pure" sway's code, so you may have to decide whether you want the code to be scroll-specific, or go upstream and submit a PR to sway. I am good either way, it is completely your choice. |
|
thanks for taking a look! where can I see the comments? |
Don't you see them here and in the Files Changed tab? It is just one comment, about enclosing the Edit: Sorry, I had forgotten to submit |
There was a problem hiding this comment.
Here, I would just enclose both into an outer if (node) to make clear both are only valid when node != NULL. Something like:
if (node) {
if (node->type == N_WORKSPACE) {
output_layer_shell_enable(node->sway_workspace->output, LAYER_SHELL_ALL);
} else if (node->type == N_CONTAINER) {
struct sway_container *con = node->sway_container;
if (con->fullscreen || (fullscreen && config->fullscreen_movefocus == FULLSCREEN_MOVEFOCUS_FOLLOW)) {
container_set_fullscreen(con, FULLSCREEN_WORKSPACE);
container_set_fullscreen_container(con, FULLSCREEN_ENABLED);
arrange_root();
}
}
}I think it is OK to add this check too, even though I cannot think of a case where a view is unmapped and scroll left without a focused surface or workspace, but it is OK to add, it doesn't hurt.
There was a problem hiding this comment.
This is all good, thank you. However, you may have to decide whether to merge this into scroll or go upstream to sway, because these are all cases from sway's code. I mean, your use case would also make sway crash. I will merge it here if that is your preference, I understand a PR in sway may take a lot longer to process, but if you are also a sway user, or would rather submit a PR there, I can also merge it later on when it gets accepted, which I cannot think of a reason why it wouldn't.
seat_get_focus()can return NULL when the focus stack is empty. A few call sites don't check for this and just dereference the result, which crashes scroll.I hit this for two main reasons:
linux-wallpaperenginecrashing (according to logs), and restarting noctalia shell (necessary after an update). For thelinux-wallpaperenginecrashes, each crash is an abrupt client disconnect, which leaves the seat with a stalehas_focusor empty focus stack. Then whatever touches focus next dereferences NULL and crashes scroll.I added NULL checks in
seat_set_workspace_focus,seat_set_focus_surface,seat_unfocus_unless_client, andview_unmap. The first two caused crashes (coredumps pasted below), the other two sites, I haven't gotten a crash from yet but added checks to be safe.Coredumps:
I cannot remember how i triggered this one:
Mouse click on empty container (clicked wallpaper, likely was just after a wallpaper engine crash or something):
IPC workspace switch (with noctalia workspace widget):
Layer surface teardown (restarted noctalia shell):