Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix GH-16292: Segmentation fault in ext/xmlreader/php_xmlreader.c:1282
This commit is contained in:
Niels Dossche 2024-10-08 20:58:26 +02:00
commit dd0ced3046
No known key found for this signature in database
GPG Key ID: B8A8AD166DF0E2E5
3 changed files with 34 additions and 2 deletions

View File

@ -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; \

View File

@ -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;
}

View File

@ -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)