From 3bce5dfc9f288ffcfa045ae0a80bcc015d0966c5 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 21 Apr 2018 19:04:48 +0100 Subject: [PATCH] Fix segfaults in wlr_surface_is_* --- types/wlr_wl_shell.c | 3 ++- types/wlr_xdg_shell.c | 5 +++-- types/wlr_xdg_shell_v6.c | 5 +++-- xwayland/xwm.c | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index 45a80221..5e4c24e7 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -13,7 +13,8 @@ static const char *wlr_wl_shell_surface_role = "wl-shell-surface"; bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface) { - return strcmp(surface->role, wlr_wl_shell_surface_role) == 0; + return surface->role != NULL && + strcmp(surface->role, wlr_wl_shell_surface_role) == 0; } struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface( diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index 1aa964a6..8d424f3b 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -17,8 +17,9 @@ static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; static const char *wlr_desktop_xdg_popup_role = "xdg_popup"; bool wlr_surface_is_xdg_surface(struct wlr_surface *surface) { - return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || - strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0; + return surface->role != NULL && + (strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || + strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0); } struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface( diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 3bd845d3..22b387f1 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -17,8 +17,9 @@ static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel_v6"; static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6"; bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface) { - return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || - strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0; + return surface->role != NULL && + (strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || + strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0); } struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 77dc0797..599006ae 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -80,7 +80,8 @@ const char *atom_map[ATOM_LAST] = { const char *wlr_xwayland_surface_role = "wlr_xwayland_surface"; bool wlr_surface_is_xwayland_surface(struct wlr_surface *surface) { - return strcmp(surface->role, wlr_xwayland_surface_role) == 0; + return surface->role != NULL && + strcmp(surface->role, wlr_xwayland_surface_role) == 0; } struct wlr_xwayland_surface *wlr_xwayland_surface_from_wlr_surface(