From 4f463faefbd564bbc854dcec1318acc9e7890733 Mon Sep 17 00:00:00 2001 From: bornmw Date: Sat, 10 Oct 2026 10:52:32 -0400 Subject: [PATCH] wcm: print an error and exit on empty elements in metadata The option desc parser dereferenced n->children->content for and <_name> elements without a null check. An empty element (no children) segfaulted wcm at startup. Following the handling accepted in #126: print an error naming the plugin and option, and exit cleanly. The same is_value/is_name computation is now done once before the type branches. --- src/metadata.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/metadata.cpp b/src/metadata.cpp index 65fac8a..40e3298 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -272,10 +272,20 @@ Option::Option(xmlNode *cur_node, Plugin *plugin) { if (n->type == XML_ELEMENT_NODE) { + std::string elem_name = (char*)n->name; + int is_value = (elem_name == "value"); + int is_name = (elem_name == "_name"); + if ((is_value || is_name) && !n->children) + { + printf("ERROR: [%s] empty <%s> element in option '%s' " + "description; fix the plugin metadata\n", + plugin->name.c_str(), elem_name.c_str(), + this->name.c_str()); + exit(1); + } + if (this->type == OPTION_TYPE_INT) { - int is_value = (std::string((char*)n->name) == "value"); - int is_name = (std::string((char*)n->name) == "_name"); if (!li && (is_value || is_name)) { li = std::make_unique(); @@ -293,8 +303,6 @@ Option::Option(xmlNode *cur_node, Plugin *plugin) } } else if (this->type == OPTION_TYPE_STRING) { - int is_value = (std::string((char*)n->name) == "value"); - int is_name = (std::string((char*)n->name) == "_name"); if (!ls && (is_value || is_name)) { ls = std::make_unique();