Fix #79922: Crash after multiple calls to xml_parser_free() #5969
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We must not call
zend_list_delete()
in resource closer functionsexposed to userland, because decreasing the refcount there leads to
use-after-free scenarios. In this case, commit 4a42fbb worked for
typical use-cases where
xml_parser_free()
has been called exactlyonce for the resource, because there is an internal zval (
->index
)referencing the same resource which already increased the refcount by
one. However, when
xml_parser_free()
is called multiple times on thesame XML parser resource, the resource would be freed prematurely.
Instead we forcefully close the resource in
xml_parser_free()
. Wealso could decrease the refcount of the resource there, but that would
require to call
xml_parser_free()
which is somewhat uncommon, andwould be particularly bad wrt. PHP 8 where that function is a NOP, and
as such doesn't have to be called. So we do no longer increase the
refcount of the resource when copying it to the internal zval, and let
the usualy refcounting semantics take care of the resource destruction.
[1] http://git.php.net/?p=php-src.git;a=commit;h=4a42fbbbc73aad7427aef5c89974d1833636e082