Skip to content

Commit 852e402

Browse files
committed
Fix: libcib: Full-CIB replace op no longer segfaults with cib_xpath
Previously, a CIB replace operation targeting the full CIB would fail with a segmentation fault if the cib_xpath flag were set (or if --xpath were used with cibadmin). Presumably this is because process_replace_xpath() was freeing the CIB, leaving no reference to it, and possibly dereferencing more nodes in the document as it continued processing any remaining XPath search results. Now, a full CIB replacement with XPath succeeds if the replacement CIB is well-formed and is of a newer version, and it appears to fail sanely otherwise. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent f4e20d3 commit 852e402

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/cib/cib_ops.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,11 @@ replace_cib(xmlNode *request, xmlNode *input, xmlNode **cib)
828828

829829
static int
830830
process_replace_xpath(const char *op, int options, const char *xpath,
831-
xmlNode *input, xmlNode *cib)
831+
xmlNode *request, xmlNode *input, xmlNode **cib)
832832
{
833833
int num_results = 0;
834834
int rc = pcmk_rc_ok;
835-
xmlXPathObject *xpath_obj = pcmk__xpath_search(cib->doc, xpath);
835+
xmlXPathObject *xpath_obj = pcmk__xpath_search((*cib)->doc, xpath);
836836

837837
num_results = pcmk__xpath_num_results(xpath_obj);
838838
if (num_results == 0) {
@@ -855,6 +855,11 @@ process_replace_xpath(const char *op, int options, const char *xpath,
855855
pcmk__debug("Processing %s op for %s with %s", op, xpath, path);
856856
free(path);
857857

858+
if (match == *cib) {
859+
rc = replace_cib(request, input, cib);
860+
break;
861+
}
862+
858863
parent = match->parent;
859864

860865
pcmk__xml_free(match);
@@ -912,7 +917,7 @@ cib__process_replace(const char *op, int options, const char *section,
912917
xmlNode **answer)
913918
{
914919
if (pcmk__is_set(options, cib_xpath)) {
915-
return process_replace_xpath(op, options, section, input, *cib);
920+
return process_replace_xpath(op, options, section, req, input, cib);
916921
}
917922

918923
return process_replace_section(section, req, input, cib);

0 commit comments

Comments
 (0)