From 023427b4f4bedbd74697e42261033932738b2fd8 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Fri, 27 Dec 2024 22:37:35 +0000 Subject: [PATCH] view: fix NULL string_prop crash ...when app_id is NULL. Make sure view_get_string_prop() never returns NULL because it is so easy to misuse. Same for the respective xwayland/xdg impl methods in case anyone decides to (incorrectly) call them directly in future. Fixes: #2453 --- src/view.c | 4 +++- src/xdg.c | 4 ++-- src/xwayland.c | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/view.c b/src/view.c index 6047dd05..209dd7fa 100644 --- a/src/view.c +++ b/src/view.c @@ -2335,13 +2335,15 @@ view_has_strut_partial(struct view *view) view->impl->has_strut_partial(view); } +/* Note: It is safe to assume that this function never returns NULL */ const char * view_get_string_prop(struct view *view, const char *prop) { assert(view); assert(prop); if (view->impl->get_string_prop) { - return view->impl->get_string_prop(view, prop); + const char *ret = view->impl->get_string_prop(view, prop); + return ret ? ret : ""; } return ""; } diff --git a/src/xdg.c b/src/xdg.c index bb6d9eb6..e4f41e32 100644 --- a/src/xdg.c +++ b/src/xdg.c @@ -660,10 +660,10 @@ xdg_toplevel_view_get_string_prop(struct view *view, const char *prop) } if (!strcmp(prop, "title")) { - return xdg_toplevel->title; + return xdg_toplevel->title ? xdg_toplevel->title : ""; } if (!strcmp(prop, "app_id")) { - return xdg_toplevel->app_id; + return xdg_toplevel->app_id ? xdg_toplevel->app_id : ""; } return ""; } diff --git a/src/xwayland.c b/src/xwayland.c index 5ebc730a..5fef5ee8 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -485,10 +485,10 @@ xwayland_view_get_string_prop(struct view *view, const char *prop) } if (!strcmp(prop, "title")) { - return xwayland_surface->title; + return xwayland_surface->title ? xwayland_surface->title : ""; } if (!strcmp(prop, "class")) { - return xwayland_surface->class; + return xwayland_surface->class ? xwayland_surface->class : ""; } /* * Use the WM_CLASS 'instance' (1st string) for the app_id. Per @@ -500,7 +500,7 @@ xwayland_view_get_string_prop(struct view *view, const char *prop) * here since we use the app_id for icon lookups. */ if (!strcmp(prop, "app_id")) { - return xwayland_surface->instance; + return xwayland_surface->instance ? xwayland_surface->instance : ""; } return ""; } -- 2.52.0