mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-16593: Assertion failure in DOM->replaceChild
This is already forbidden by libxml, but this condition isn't properly checked; so the return value and lack of error makes it seem like it worked while it actually didn't. Furthermore, this can break assumptions and assertions later on. Closes GH-16596.
This commit is contained in:
1
NEWS
1
NEWS
@@ -39,6 +39,7 @@ PHP NEWS
|
||||
. Fixed bug GH-16533 (Segfault when adding attribute to parent that is not
|
||||
an element). (nielsdos)
|
||||
. Fixed bug GH-16535 (UAF when using document as a child). (nielsdos)
|
||||
. Fixed bug GH-16593 (Assertion failure in DOM->replaceChild). (nielsdos)
|
||||
|
||||
- EXIF:
|
||||
. Fixed bug GH-16409 (Segfault in exif_thumbnail when not dealing with a
|
||||
|
||||
@@ -1093,6 +1093,13 @@ PHP_METHOD(DOMNode, replaceChild)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* This is already disallowed by libxml, but we should check it here to avoid
|
||||
* breaking assumptions and assertions. */
|
||||
if ((oldchild->type == XML_ATTRIBUTE_NODE) != (newchild->type == XML_ATTRIBUTE_NODE)) {
|
||||
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (oldchild->parent != nodep) {
|
||||
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
|
||||
RETURN_FALSE;
|
||||
|
||||
22
ext/dom/tests/gh16593.phpt
Normal file
22
ext/dom/tests/gh16593.phpt
Normal file
@@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
GH-16593 (Assertion failure in DOM->replaceChild)
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$root = $doc->appendChild($doc->createElement('root'));
|
||||
$child = $root->appendChild($doc->createElement('child'));
|
||||
try {
|
||||
$root->replaceChild($doc->createAttribute('foo'), $child);
|
||||
} catch (DOMException $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
echo $doc->saveXML();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Hierarchy Request Error
|
||||
<?xml version="1.0"?>
|
||||
<root><child/></root>
|
||||
Reference in New Issue
Block a user