]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: fix segfault with toplevel <separator>
authortokyo4j <hrak1529@gmail.com>
Sun, 3 Aug 2025 07:55:59 +0000 (16:55 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 3 Aug 2025 14:07:35 +0000 (15:07 +0100)
Before this patch, labwc crashed menu.xml like this:

<openbox_menu>
  <separator />
</openbox_menu>

src/menu/menu.c

index dd902bc24f3612d89eb7ba0b69533bfc5ff9456c..8d80231fde396c5ce011db2593e58c404d7cef07 100644 (file)
@@ -269,6 +269,8 @@ item_create_scene(struct menuitem *menuitem, int *item_y)
 static struct menuitem *
 separator_create(struct menu *menu, const char *label)
 {
+       assert(menu);
+
        struct menuitem *menuitem = znew(*menuitem);
        menuitem->parent = menu;
        menuitem->selectable = false;
@@ -754,6 +756,11 @@ xml_tree_walk(struct menu_parse_context *ctx, xmlNode *node)
                        continue;
                }
                if (!strcasecmp((char *)n->name, "separator")) {
+                       if (!ctx->menu) {
+                               wlr_log(WLR_ERROR,
+                                       "ignoring <separator> without parent <menu>");
+                               continue;
+                       }
                        handle_separator_element(ctx, n);
                        continue;
                }