From 54fde9f7c0ae426550356c6e3f7474a063e3968c Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Fri, 3 Jun 2022 02:19:31 +0200 Subject: [PATCH] Prevent missing direction arguments to segfault labwc Reported-by: @Flrian Backport of 986ab70780efd3e4f16f139e4a11d50d75e8ca5a --- src/action.c | 12 ++++++++++-- src/view.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/action.c b/src/action.c index e0a6657b..f898029c 100644 --- a/src/action.c +++ b/src/action.c @@ -178,10 +178,18 @@ action(struct view *activator, struct server *server, struct wl_list *actions, u wl_display_terminate(server->wl_display); break; case ACTION_TYPE_MOVE_TO_EDGE: - view_move_to_edge(view, action->arg); + if (action->arg) { + view_move_to_edge(view, action->arg); + } else { + wlr_log(WLR_ERROR, "Missing argument for MoveToEdge"); + } break; case ACTION_TYPE_SNAP_TO_EDGE: - view_snap_to_edge(view, action->arg); + if (action->arg) { + view_snap_to_edge(view, action->arg); + } else { + wlr_log(WLR_ERROR, "Missing argument for SnapToEdge"); + } break; case ACTION_TYPE_NEXT_WINDOW: server->cycle_view = diff --git a/src/view.c b/src/view.c index a101d97c..eb63c84f 100644 --- a/src/view.c +++ b/src/view.c @@ -447,6 +447,10 @@ view_move_to_edge(struct view *view, const char *direction) wlr_log(WLR_ERROR, "no output"); return; } + if (!direction) { + wlr_log(WLR_ERROR, "invalid edge"); + return; + } struct border border = view_border(view); struct wlr_box usable = output_usable_area_in_layout_coords(output); if (usable.height == output->wlr_output->height && output->wlr_output->scale != 1) { @@ -469,6 +473,9 @@ view_move_to_edge(struct view *view, const char *direction) } else if (!strcasecmp(direction, "down")) { x = view->x; y = usable.y + usable.height - view->h - border.bottom - rc.gap; + } else { + wlr_log(WLR_ERROR, "invalid edge"); + return; } view_move(view, x, y); } @@ -505,6 +512,9 @@ view_edge_invert(enum view_edge edge) static enum view_edge view_edge_parse(const char *direction) { + if (!direction) { + return VIEW_EDGE_INVALID; + } if (!strcasecmp(direction, "left")) { return VIEW_EDGE_LEFT; } else if (!strcasecmp(direction, "up")) {