Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix GH-16292: Segmentation fault in ext/xmlreader/php_xmlreader.c:1282
  • Loading branch information
nielsdos committed Oct 8, 2024
2 parents c8194a1 + 1f84f5c commit dd0ced3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/dom/xml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
__intern = Z_LIBXML_NODE_P(__id); \
if (UNEXPECTED(__intern->node == NULL)) { \
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", \
ZSTR_VAL(__intern->std.ce->name));\
ZSTR_VAL(Z_OBJCE_P(__zv)->name));\
RETURN_NULL();\
} \
__ptr = (__prtype)__intern->node->node; \
Expand Down
8 changes: 7 additions & 1 deletion ext/xmlreader/php_xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,13 @@ PHP_METHOD(XMLReader, expand)
}

if (basenode != NULL) {
NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj);
/* Note: cannot use NODE_GET_OBJ here because of the wrong return type */
domobj = Z_LIBXML_NODE_P(basenode);
if (UNEXPECTED(domobj->node == NULL)) {
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(Z_OBJCE_P(basenode)->name));
RETURN_FALSE;
}
node = domobj->node->node;
docp = node->doc;
}

Expand Down
26 changes: 26 additions & 0 deletions ext/xmlreader/tests/gh16292.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-16292 (Segmentation fault in ext/xmlreader/php_xmlreader.c:1282)
--EXTENSIONS--
dom
xmlreader
--FILE--
<?php

$character_data = new DOMCharacterData();
$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
<books><book>new book</book></books>';
$reader = new XMLReader();
$reader->XML($xmlstring);
while ($reader->read()) {
if ($reader->localName == "book") {
var_dump($reader->expand($character_data));
}
}

?>
--EXPECTF--
Warning: XMLReader::expand(): Couldn't fetch DOMCharacterData in %s on line %d
bool(false)

Warning: XMLReader::expand(): Couldn't fetch DOMCharacterData in %s on line %d
bool(false)

0 comments on commit dd0ced3

Please sign in to comment.