Skip to content

metadata: guard all element-content derefs with node_text() helper - #127

Closed
bornmw wants to merge 1 commit into
WayfireWM:masterfrom
bornmw:fix-empty-desc-value
Closed

bornmw wants to merge 1 commit into
WayfireWM:masterfrom
bornmw:fix-empty-desc-value

Conversation

@bornmw

@bornmw bornmw commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #126 — wcm segfaults at startup when a loaded plugin's metadata contains a metadata element with empty content (<value></value>, <_short></_short>, etc.).

Root cause

A metadata element with no text content leaves node->children == NULL in libxml2, so reading node->children->content is a null deref → SIGSEGV.

The get_plugin_data / Option constructors already guarded against this for <min>, <max>, <precision>, <hint>, <default> and <category> via if (!node->children) continue; — but the guard was missing for several other element types:

Change

Add a small helper that centralises the "is it empty?" logic:

static xmlChar *
node_text(const xmlNode *node)
{
    return (node->children) ? node->children->content : nullptr;
}

and use it at every site, with a null-check before use. The previously-guarded sites are untouched; the previously-unguarded ones now call node_text() and continue when it returns NULL.

This is option 1 from the discussion: a DRY helper rather than a blanket top-of-loop guard (which would change semantics for <default></default>, where an empty string is a valid distinct value).

Testing

  • No unit-test framework exists in wcm; CI is build-on-Alpine + uncrustify style check. The change is a simple helper + identical guard/node_text substitutions, so it is style-clean.
  • Reproduced the crash with the metadata from the issue before the fix; after the fix wcm starts normally with that metadata.
  • Verified all remaining node->children->content sites in the file are within an existing if (!node->children) guard.

@bornmw
bornmw force-pushed the fix-empty-desc-value branch from 6719499 to 08542db Compare October 8, 2026 11:45
@bornmw bornmw changed the title metadata: skip empty desc children in get_plugin_data metadata: guard all element-content derefs with node_text() helper Oct 8, 2026
A metadata element with empty content (e.g. <value></value>,
<_short></_short>) leaves node->children == NULL in libxml2, so reading
node->children->content is a null deref that segfaults wcm at startup.

The same function already guarded this for <min>/<max>/<precision>/
<hint>/<default>/<category> via 'if (!node->children) continue;', but the
guard was missing for <_short>, <_long>, <type> (dynamic-list), the
<desc> child loop, and the plugin/group-level <_short>/<_long> nodes.

Add a small helper:

    static xmlChar *node_text(const xmlNode *node)
    {
        return (node->children) ? node->children->content : nullptr;
    }

and use it at every site, with a null-check before use. The 'is it
empty?' logic now lives in one place instead of being copy-pasted.

Fixes WayfireWM#126
@soreau

soreau commented Oct 8, 2026

Copy link
Copy Markdown
Member

NAK. The metadata should be fixed, not consumers of the metadata. It does not make sense to have an empty <element> in the first place. Thank you for your interest. Closes #126.

@soreau soreau closed this Oct 8, 2026
@bornmw

bornmw commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

NAK. The metadata should be fixed, not consumers of the metadata. It does not make sense to have an empty <element> in the first place. Thank you for your interest. Closes #126.

There are already checks for empty '<element>' in the code, e.g. <min>/<max>/<precision>/<hint>/<category>
So it does make sense to have empty elements
Same case with the <default> - it already treats empty content as a valid value, and does not segfault
Why would you guard some fields and let others segfault?

@soreau

soreau commented Oct 8, 2026

Copy link
Copy Markdown
Member

I use wcm with all upstream metadata and it does not crash. Can you show an example of the offending metadata you are using to crash it?

@bornmw

bornmw commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

I use wcm with all upstream metadata and it does not crash. Can you show an example of the offending metadata you are using to crash it?

I have my own plugins that are not mainstream.
I understand that the value should have something that is not empty, but segfault is definitely not the way to enforce that
It should be something like what default does - a WARN or an ERROR, but segfault?

@soreau

soreau commented Oct 8, 2026

Copy link
Copy Markdown
Member

It should be something like what default does - a WARN or an ERROR, but segfault?

I would accept a PR that prints a warning and exits in these cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wcm segfaults at startup when a loaded plugin's metadata has an empty <value> element in an option <desc>

2 participants