xref: /PHP-8.3/ext/dom/tests/gh16150.phpt (revision d4a4d2e7)
1--TEST--
2GH-16150 (Use after free in php_dom.c)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8function test($fname) {
9    $e1 = new DOMElement("E1");
10    $e2 = new DOMElement("E2");
11    $e3 = new DOMElement("E3");
12    $doc = new DOMDocument(); // Must be placed here so it is destroyed first
13    $doc->{$fname}($e3);
14    $e2->append($e1);
15    $e3->{$fname}($e2);
16    echo $doc->saveXML();
17}
18
19test('appendChild');
20test('insertBefore');
21
22?>
23--EXPECT--
24<?xml version="1.0"?>
25<E3><E2><E1/></E2></E3>
26<?xml version="1.0"?>
27<E3><E2><E1/></E2></E3>
28