Skip to content

Commit dd4c0f6

Browse files
committed
tree: Fix xmlTextMerge with NULL args
Restore pre-2.13 behavior. Fixes #875.
1 parent 54c3d42 commit dd4c0f6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

fuzz/api.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,11 +2461,14 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
24612461
first = getNode(0);
24622462
second = getNode(1);
24632463
argsOk =
2464-
(first != NULL && first->type == XML_TEXT_NODE &&
2465-
second != NULL && second->type == XML_TEXT_NODE &&
2466-
first != second &&
2467-
first->name == second->name);
2468-
if (argsOk) {
2464+
first == NULL ?
2465+
second != NULL :
2466+
second == NULL ||
2467+
(first->type == XML_TEXT_NODE &&
2468+
second->type == XML_TEXT_NODE &&
2469+
first != second &&
2470+
first->name == second->name);
2471+
if (argsOk && second != NULL) {
24692472
if (second->parent != NULL)
24702473
parent = second->parent;
24712474
else
@@ -2474,7 +2477,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
24742477
}
24752478
res = xmlTextMerge(first, second);
24762479
oomReport = (argsOk && res == NULL);
2477-
if (res != NULL) {
2480+
if (res != NULL && first != NULL) {
24782481
removeNode(second);
24792482
dropNode(parent);
24802483
checkContent(first);

tree.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5790,15 +5790,21 @@ xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) {
57905790
* @first: the first text node
57915791
* @second: the second text node being merged
57925792
*
5793-
* Merge the second text node into the first. The second node is
5794-
* unlinked and freed.
5793+
* Merge the second text node into the first. If @first is NULL,
5794+
* @second is returned. Otherwise, the second node is unlinked and
5795+
* freed.
57955796
*
57965797
* Returns the first text node augmented or NULL in case of error.
57975798
*/
57985799
xmlNodePtr
57995800
xmlTextMerge(xmlNodePtr first, xmlNodePtr second) {
5800-
if ((first == NULL) || (first->type != XML_TEXT_NODE) ||
5801-
(second == NULL) || (second->type != XML_TEXT_NODE) ||
5801+
if (first == NULL)
5802+
return(second);
5803+
if (second == NULL)
5804+
return(first);
5805+
5806+
if ((first->type != XML_TEXT_NODE) ||
5807+
(second->type != XML_TEXT_NODE) ||
58025808
(first == second) ||
58035809
(first->name != second->name))
58045810
return(NULL);

0 commit comments

Comments
 (0)