From c83aed67284fe4f51e79a4fb638ac9c91dbef337 Mon Sep 17 00:00:00 2001 From: project-repo Date: Thu, 29 Dec 2022 16:09:33 +0100 Subject: [PATCH] Remove view_title - Do not set window title, as it cannot be read - Print PID in event instead of title to prevent information leaks --- keybinding.c | 16 +++++++--------- output.c | 13 ------------- seat.c | 4 ---- view.c | 19 +++++-------------- view.h | 4 +--- xdg_shell.c | 14 ++++++++------ xwayland.c | 12 ++++++------ 7 files changed, 27 insertions(+), 55 deletions(-) diff --git a/keybinding.c b/keybinding.c index 9106442..a9047e5 100644 --- a/keybinding.c +++ b/keybinding.c @@ -838,9 +838,7 @@ print_view(struct cg_view *view) { uint32_t nmemb = 4; outp_str.str_arr = calloc(nmemb, sizeof(char *)); print_str(&outp_str, "\"id\": %d,\n", view->id); - char *title_str = view->impl->get_title(view); - print_str(&outp_str, "\"title\": \"%s\",\n", - title_str == NULL ? "" : title_str); + print_str(&outp_str, "\"pid\": \"%d\",\n", view->impl->get_pid(view)); print_str(&outp_str, "\"coords\": {\"x\":%d,\"y\":%d},\n", view->ox, view->oy); #if CG_HAS_XWAYLAND @@ -1314,18 +1312,18 @@ keybinding_move_view_to_output(struct cg_server *server, int output_num) { workspace_tile_update_view(ws->focused_tile,view); seat_set_focus(server->seat, view); } - char *view_title = ""; + pid_t view_pid = -1; int view_id = -1; if(view != NULL) { - view_title = view->impl->get_title(view); + view_pid = view->impl->get_pid(view); view_id = view->id; } ipc_send_event( server, "{\"event_name\":\"move_view_to_output\",\"view_id\":\"%d\",\"old_" - "output\":\"%s\",\"new_output\":\"%s\",\"view_title\":\"%s\"}", + "output\":\"%s\",\"new_output\":\"%s\",\"view_pid\":\"%d\"}", view_id, old_outp->wlr_output->name, - server->curr_output->wlr_output->name, view_title); + server->curr_output->wlr_output->name, view_pid); } void @@ -1358,10 +1356,10 @@ keybinding_move_view_to_workspace(struct cg_server *server, uint32_t ws) { ipc_send_event(server, "{\"event_name\":\"move_view_to_ws\",\"view_id\":\"%d\"," "\"old_workspace\":\"%d\",\"new_workspace\":\"%d\"," - "\"output\":\"%s\",\"view_title\":\"%s\"}", + "\"output\":\"%s\",\"view_pid\":\"%d\"}", view == NULL ? -1 : (int)view->id, old_ws, ws, server->curr_output->wlr_output->name, - view == NULL ? "" : view->impl->get_title(view)); + view == NULL ? 0 : view->impl->get_pid(view)); } void diff --git a/output.c b/output.c index ed422b9..ed7855f 100644 --- a/output.c +++ b/output.c @@ -576,16 +576,3 @@ handle_new_output(struct wl_listener *listener, void *data) { #if CG_HAS_FANALYZE #pragma GCC diagnostic pop #endif - -void -output_set_window_title(struct cg_output *output, const char *title) { - struct wlr_output *wlr_output = output->wlr_output; - - if(wlr_output_is_wl(wlr_output)) { - wlr_wl_output_set_title(wlr_output, title); -#if WLR_HAS_X11_BACKEND - } else if(wlr_output_is_x11(wlr_output)) { - wlr_x11_output_set_title(wlr_output, title); -#endif - } -} diff --git a/seat.c b/seat.c index 03a940c..875287b 100644 --- a/seat.c +++ b/seat.c @@ -1040,10 +1040,6 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) { } view_activate(view, true); - char *title = view_get_title(view); - - output_set_window_title(server->curr_output, title); - free(title); struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(wlr_seat); wlr_seat_keyboard_end_grab(wlr_seat); diff --git a/view.c b/view.c index b0fabe2..8afb697 100644 --- a/view.c +++ b/view.c @@ -52,15 +52,6 @@ view_get_prev_view(struct cg_view *view) { return prev; } -char * -view_get_title(const struct cg_view *view) { - const char *title = view->impl->get_title(view); - if(!title) { - return NULL; - } - return strndup(title, strlen(title)); -} - bool view_is_primary(const struct cg_view *view) { return view->impl->is_primary(view); @@ -113,7 +104,7 @@ view_unmap(struct cg_view *view) { uint32_t tile_id = 0; uint32_t ws = view->workspace->num; char *output_name = view->workspace->output->wlr_output->name; - char *title = view->impl->get_title(view); + pid_t pid = view->impl->get_pid(view); /* If the view is not mapped, do nothing */ if(view->wlr_surface == NULL) { return; @@ -162,8 +153,8 @@ view_unmap(struct cg_view *view) { ipc_send_event( view->workspace->server, "{\"event_name\":\"view_unmap\",\"view_id\":\"%d\",\"tile_id\":\"%d\"," - "\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", - id, tile_id, ws + 1, output_name, title); + "\"workspace\":\"%d\",\"output\":\"%s\",\"view_pid\":\"%d\"}", + id, tile_id, ws + 1, output_name, pid); } void @@ -205,9 +196,9 @@ view_map(struct cg_view *view, struct wlr_surface *surface, ipc_send_event( output->server, "{\"event_name\":\"view_map\",\"view_id\":\"%d\",\"tile_id\":\"%d\"," - "\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", + "\"workspace\":\"%d\",\"output\":\"%s\",\"view_pid\":\"%d\"}", view->id, tile_id, view->workspace->num + 1, - view->workspace->output->wlr_output->name, view->impl->get_title(view)); + view->workspace->output->wlr_output->name, view->impl->get_pid(view)); } void diff --git a/view.h b/view.h index 47a5221..df41547 100644 --- a/view.h +++ b/view.h @@ -35,7 +35,7 @@ struct cg_view { }; struct cg_view_impl { - char *(*get_title)(const struct cg_view *view); + pid_t (*get_pid)(const struct cg_view *view); bool (*is_primary)(const struct cg_view *view); void (*activate)(struct cg_view *view, bool activate); void (*close)(struct cg_view *view); @@ -43,8 +43,6 @@ struct cg_view_impl { void (*destroy)(struct cg_view *view); }; -char * -view_get_title(const struct cg_view *view); struct cg_tile * view_get_tile(const struct cg_view *view); bool diff --git a/xdg_shell.c b/xdg_shell.c index c6ce196..4c32142 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -106,11 +106,13 @@ xdg_shell_view_from_const_view(const struct cg_view *view) { return (const struct cg_xdg_shell_view *)view; } -static char * -get_title(const struct cg_view *view) { - const struct cg_xdg_shell_view *xdg_shell_view = - xdg_shell_view_from_const_view(view); - return xdg_shell_view->xdg_surface->toplevel->title; +static pid_t +get_pid(const struct cg_view *view) { + pid_t pid; + struct wl_client *client = + wl_resource_get_client(view->wlr_surface->resource); + wl_client_get_credentials(client, &pid, NULL, NULL); + return pid; } static bool @@ -198,7 +200,7 @@ handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *_data) { view_destroy(view); } -static const struct cg_view_impl xdg_shell_view_impl = {.get_title = get_title, +static const struct cg_view_impl xdg_shell_view_impl = {.get_pid = get_pid, .is_primary = is_primary, .activate = activate, diff --git a/xwayland.c b/xwayland.c index 88db55f..42344a0 100644 --- a/xwayland.c +++ b/xwayland.c @@ -44,11 +44,11 @@ xwayland_view_should_manage(const struct cg_view *view) { return !xwayland_surface->override_redirect; } -static char * -get_title(const struct cg_view *view) { - const struct cg_xwayland_view *xwayland_view = - xwayland_view_from_const_view(view); - return xwayland_view->xwayland_surface->title; +static pid_t +get_pid(const struct cg_view *view) { + struct wlr_xwayland_surface *surf = + wlr_xwayland_surface_from_wlr_surface(view->wlr_surface); + return surf->pid; } static bool @@ -160,7 +160,7 @@ handle_xwayland_surface_destroy(struct wl_listener *listener, void *_data) { } static const struct cg_view_impl xwayland_view_impl = { - .get_title = get_title, + .get_pid = get_pid, .is_primary = is_primary, .activate = activate, .close = close,