Skip to content

Fix GH-15868: Assertion failure in xml_parse_into_struct after exception #15879

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ext/xml/tests/gh15868.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
GH-15868 (Assertion failure in xml_parse_into_struct after exception)
--EXTENSIONS--
xml
--FILE--
<?php
$parser = xml_parser_create();
xml_set_element_handler($parser,
function ($parser, $name, $attrs) {
throw new Error('stop 1');
}, function ($parser, $name) {
}
);
try {
xml_parse_into_struct($parser, "<container/>", $values, $tags);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

$parser = xml_parser_create();
xml_set_element_handler($parser,
function ($parser, $name, $attrs) {
}, function ($parser, $name) {
throw new Error('stop 2');
}
);
try {
xml_parse_into_struct($parser, "<container/>", $values, $tags);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

$parser = xml_parser_create();
xml_set_character_data_handler($parser, function() {
throw new Error('stop 3');
});
try {
xml_parse_into_struct($parser, "<root><![CDATA[x]]></root>", $values, $tags);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
stop 1
stop 2
stop 3
6 changes: 3 additions & 3 deletions ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
zval_ptr_dtor(&retval);
}

if (!Z_ISUNDEF(parser->data)) {
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
if (parser->level <= XML_MAXLEVEL) {
zval tag, atr;
int atcnt = 0;
Expand Down Expand Up @@ -699,7 +699,7 @@ void _xml_endElementHandler(void *userData, const XML_Char *name)
zval_ptr_dtor(&retval);
}

if (!Z_ISUNDEF(parser->data)) {
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
zval tag;

if (parser->lastwasopen) {
Expand Down Expand Up @@ -747,7 +747,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
zval_ptr_dtor(&retval);
}

if (Z_ISUNDEF(parser->data)) {
if (Z_ISUNDEF(parser->data) || EG(exception)) {
return;
}

Expand Down
Loading