-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix bug #80602 #81642 GH-9142 #8729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
your fix looks correct but maybe @smalyshev would like to have a look first. |
I think it is a fix worth having, the UAF issue is real if @cmb69 or another dom sensei can look at it, it would be appreciated :-) |
Indeed, that UAF is ugly, but I'm not sure whether this patch wouldn't leak memory. I'll have a closer look ASAP. |
Not really sure what to do here; apparently, the implementation is broken. E.g. $doc = new \DOMDocument();
$doc->loadXML('<a>foo<last/></a>');
$target = $doc->documentElement->firstChild;
$target->before($target, 'baz', 'cat');
echo $doc->saveXML($doc->documentElement).PHP_EOL; segfaults with and without the patch. Or the following: $doc = new \DOMDocument();
$doc->loadXML('<a>foo<last/></a>');
$target = $doc->documentElement->lastChild;
$target->before('baz', 'cat', $target);
echo $doc->saveXML($doc->documentElement).PHP_EOL; hangs without the patch, and still has a double free with it. But besides that, it outputs
|
Confusingly, let me see what caused the segment fault. |
Hi, I have a question. @cmb69 $doc = new \DOMDocument();
$doc->loadXML('<a>foo<last/></a>');
$target = $doc->documentElement->firstChild;
$target->before($target, 'baz', 'cat');
echo $doc->saveXML($doc->documentElement).PHP_EOL; |
I think that code should output: |
Thanks. |
Thank you! On a quick glance, this looks much better. Maybe @beberlei wants to review. |
Thanks. |
I gave a shot at your branch locally, no leaks neither. |
Since it is a bugfix there is still a bit time :-) however, at worse, @cmb69 will have the final word. |
@devnexen @cmb69 @beberlei @smalyshev |
@beberlei |
This furthermore fixes the logic error explained in #8729 (comment) Closes GH-10682.
Thanks for your interest in ext/dom. |
https://bugs.php.net/bug.php?id=80602
If the number of parameters is greater than or equal to three,
xmlNewDocText
function always returns a pointer that point to$doc->documentElement->firstChild
.https://bugs.php.net/bug.php?id=81642
#9142