1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-15868: Assertion failure in xml_parse_into_struct after exception

Upon unwinding from an exception, the parser state is not stable, we
should not continue updating the values if an exception was thrown.

Closes GH-15879.
This commit is contained in:
Niels Dossche
2024-09-13 18:22:38 +02:00
parent 5b2d80bc79
commit 6c82ca2182
2 changed files with 49 additions and 3 deletions

View File

@@ -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

View File

@@ -622,7 +622,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;
@@ -693,7 +693,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) {
@@ -741,7 +741,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;
}