HomeClusterLabs Projects

Low: libcrmcommon: replace_xml_node() segfaults when doc is shared

Description

Low: libcrmcommon: replace_xml_node() segfaults when doc is shared

If the child and update arguments share the same doc, replace_xml_node()
will seg fault during its free_xml(old) call. The exact cause is
difficult to trace; it lies somewhere in the intricacies of libxml2.
If memory serves, the seg fault occurs in a libxml2 call to
DICT_FREE(doc->name), but it's not obvious why that's a problem.

This doesn't cause any known issues with existing code, but it would be
a problem in future commits that involve CIB replaces without making a
copy beforehand (extending cib_zero_copy logic to cib_file and adding
cib_transaction support to cib_file).

The fix is to skip assigning old to the tmp doc (only one line). It
doesn't need to be attached to a doc after it's been replaced. It can
simply be freed, and we can free the doc separately.

The rest of the changes are for readability.

Ref T185

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Jun 8 2023, 3:37 AM
Parents
rP33f49dd57c5c: Refactor: libcib: Functionize processing cib_file request
Branches
Unknown
Tags
Unknown
Tasks
Restricted Maniphest Task