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 4e12189604
commit ac8db36543
3 changed files with 53 additions and 3 deletions

4
NEWS
View File

@@ -23,6 +23,10 @@ PHP NEWS
. Fixed bug GH-15613 (overflow on unpack call hex string repeater).
(David Carlier)
- XML:
. Fixed bug GH-15868 (Assertion failure in xml_parse_into_struct after
exception). (nielsdos)
26 Sep 2024, PHP 8.2.24
- Core:

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

@@ -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;
@@ -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) {
@@ -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;
}