diff --git a/ext/dom/xml_common.h b/ext/dom/xml_common.h index 8e5734d5a91..a63e43e92a7 100644 --- a/ext/dom/xml_common.h +++ b/ext/dom/xml_common.h @@ -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; \ diff --git a/ext/xmlreader/php_xmlreader.c b/ext/xmlreader/php_xmlreader.c index bad8804e2f5..de19695baa5 100644 --- a/ext/xmlreader/php_xmlreader.c +++ b/ext/xmlreader/php_xmlreader.c @@ -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; } diff --git a/ext/xmlreader/tests/gh16292.phpt b/ext/xmlreader/tests/gh16292.phpt new file mode 100644 index 00000000000..f3cd37e951d --- /dev/null +++ b/ext/xmlreader/tests/gh16292.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-16292 (Segmentation fault in ext/xmlreader/php_xmlreader.c:1282) +--EXTENSIONS-- +dom +xmlreader +--FILE-- + +new book'; +$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)