1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-14698: segfault on dom node after dereference.

close GH-14701
This commit is contained in:
David Carlier
2024-06-28 13:09:52 +01:00
parent 03dab7ec3d
commit 532a2604c2
3 changed files with 30 additions and 3 deletions

1
NEWS
View File

@@ -56,6 +56,7 @@ PHP NEWS
. Fixed bug #79701 (getElementById does not correctly work with duplicate
definitions). (nielsdos)
. Implemented "New ext-dom features in PHP 8.4" RFC. (nielsdos)
. Fixed GH-14698 (segfault on DOM node dereference). (David Carlier)
- Fileinfo:
. Update to libmagic 5.45. (nielsdos)

View File

@@ -0,0 +1,22 @@
--TEST--
GH-14698 crash on DOM node dereference
--EXTENSIONS--
dom
--CREDITS--
YuanchengJiang
--FILE--
<?php
$dom = new DOMDocument;
$dom->loadHTML('<span title="y">x</span><span title="z">x</span>');
$html = simplexml_import_dom($dom);
foreach ($html->body->span as $obj) {
}
$script1_dataflow = $html;
$array = ['foo'];
foreach ($array as $key => &$value) {
unset($script1_dataflow[$key]);
}
echo "DONE";
?>
--EXPECTF--
DONE

View File

@@ -329,9 +329,13 @@ PHP_LIBXML_API void php_libxml_node_free_list(xmlNodePtr node)
/* This ensures that namespace references in this subtree are defined within this subtree,
* otherwise a use-after-free would be possible when the original namespace holder gets freed. */
php_libxml_node_ptr *ptr = curnode->_private;
php_libxml_node_object *obj = ptr->_private;
if (!obj->document || obj->document->class_type < PHP_LIBXML_CLASS_MODERN) {
xmlReconciliateNs(curnode->doc, curnode);
/* Checking in case it runs out of reference */
if (ptr->_private) {
php_libxml_node_object *obj = ptr->_private;
if (!obj->document || obj->document->class_type < PHP_LIBXML_CLASS_MODERN) {
xmlReconciliateNs(curnode->doc, curnode);
}
}
}
/* Skip freeing */