Skip to content

Fix bug #79451: Using DOMDocument->replaceChild on doctype causes double free #9201

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

Closed
wants to merge 3 commits into from

Conversation

NathanFreeman
Copy link
Contributor

@NathanFreeman NathanFreeman commented Jul 30, 2022

https://bugs.php.net/bug.php?id=79451
We have to reset intSubset if replacing doctype with another doctype node.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know libxml, but the fix seems reasonable and the test works.

Only nits are coding style related.

ext/dom/node.c Outdated
@@ -1000,7 +1001,7 @@ PHP_METHOD(DOMNode, replaceChild)
zval *id, *newnode, *oldnode;
xmlNodePtr children, newchild, oldchild, nodep;
dom_object *intern, *newchildobj, *oldchildobj;
int foundoldchild = 0, stricterror;
int foundoldchild = 0, stricterror, replacedoctype = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int foundoldchild = 0, stricterror, replacedoctype = 0;
int foundoldchild = 0, stricterror;
bool replacedoctype = false;

PHP 8.0 uses C99 so might as well use bool :)

But even better would to move into the branch where it is only relevant.

@NathanFreeman NathanFreeman requested a review from Girgias August 4, 2022 14:11
@kamil-tekiela kamil-tekiela changed the title Fix bug #79451 Fix bug #79451: Using DOMDocument->replaceChild on doctype causes double free Aug 16, 2022
@Girgias Girgias closed this in 1d4300d Aug 19, 2022
@Girgias
Copy link
Member

Girgias commented Aug 19, 2022

The fix for 8.1 and above is different, and I don't know how to do it. So reoppening

@Girgias Girgias reopened this Aug 19, 2022
@iluuu1994
Copy link
Member

@Girgias I think the only think that needs to be done is switch from the skipif.inc to --EXTENSIONS--.

@Girgias
Copy link
Member

Girgias commented Aug 19, 2022

@Girgias I think the only think that needs to be done is switch from the skipif.inc to --EXTENSIONS--.

That's not where I was getting the messy merge, but @cmb69 has made a patch for 8.1 and above in #9376

@cmb69 cmb69 closed this in 6027d44 Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants