Merge branch 'PHP-8.3'

* PHP-8.3:
  Fix GH-15868: Assertion failure in xml_parse_into_struct after exception
  Fix GH-15868: Assertion failure in xml_parse_into_struct after exception
This commit is contained in:
Niels Dossche 2024-09-13 20:02:00 +02:00
commit e7b022ea17
No known key found for this signature in database
GPG Key ID: B8A8AD166DF0E2E5
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

@ -626,7 +626,7 @@ void xml_startElementHandler(void *userData, const XML_Char *name, const XML_Cha
zval_ptr_dtor(&args[2]);
}
if (!Z_ISUNDEF(parser->data)) {
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
if (parser->level <= XML_MAXLEVEL) {
zval tag, atr;
int atcnt = 0;
@ -697,7 +697,7 @@ void xml_endElementHandler(void *userData, const XML_Char *name)
zval_ptr_dtor(&args[1]);
}
if (!Z_ISUNDEF(parser->data)) {
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
zval tag;
if (parser->lastwasopen) {
@ -746,7 +746,7 @@ void xml_characterDataHandler(void *userData, const XML_Char *s, int len)
zval_ptr_dtor(&args[1]);
}
if (Z_ISUNDEF(parser->data)) {
if (Z_ISUNDEF(parser->data) || EG(exception)) {
return;
}