]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: fix NULL string_prop crash
authorJohan Malm <jgm323@gmail.com>
Fri, 27 Dec 2024 22:37:35 +0000 (22:37 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 29 Dec 2024 13:06:30 +0000 (13:06 +0000)
...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
src/xdg.c
src/xwayland.c

index 6047dd05ce5c50e3303190cfff377c3b23531ffb..209dd7fa9912710ea2baab29d84cdf9e42a87fcb 100644 (file)
@@ -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 "";
 }
index bb6d9eb65c478117e30da0385337c0b97531e466..e4f41e328bf1bfcf5ae8fd2e79615ad831e25890 100644 (file)
--- 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 "";
 }
index 5ebc730ac63aca2cb5660ca3550989e8a6bdf07a..5fef5ee85c4547c50ac0e6e8a0b91bd0a25c1e23 100644 (file)
@@ -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 "";
 }