Skip to content

Commit 0f1bf4b

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #81351: xml_parse may fail, but has no error code
2 parents a027247 + 2c6177a commit 0f1bf4b

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

ext/xml/compat.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,8 @@ XML_Parse(XML_Parser parser, const XML_Char *data, int data_len, int is_final)
563563
{
564564
int error;
565565

566-
if (parser->parser->lastError.level >= XML_ERR_WARNING) {
567-
return 0;
568-
}
569-
570566
error = xmlParseChunk(parser->parser, (char *) data, data_len, is_final);
571-
if (error) {
572-
return 0;
573-
} else {
574-
return 1;
575-
}
567+
return !error && parser->parser->lastError.level <= XML_ERR_WARNING;
576568
}
577569

578570
PHP_XML_API int

ext/xml/tests/bug73135.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ HERE;
2121
xml_parse($parser, $xml);
2222
?>
2323
--EXPECTF--
24+
Warning: xml_parse(): Parser must not be called recursively in %s%ebug73135.php on line %d
25+
26+
Warning: xml_parse(): Parser must not be called recursively in %s%ebug73135.php on line %d
27+
2428
Warning: xml_parse(): Unable to call handler ahihi() in %s%ebug73135.php on line %d
2529

2630
Warning: xml_parse(): Unable to call handler ahihi() in %s%ebug73135.php on line %d

ext/xml/tests/bug81351.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81351 (xml_parse may fail, but has no error code)
3+
--EXTENSIONS--
4+
xml
5+
--FILE--
6+
<?php
7+
$xml = <<<XML
8+
<?xml version="1.0" encoding="utf-8"?>
9+
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
10+
<soap:Body>
11+
<X xmlns="example.org">
12+
XML;
13+
14+
$parser = xml_parser_create_ns('UTF-8');
15+
$success = xml_parse($parser, $xml, false);
16+
$code = xml_get_error_code($parser);
17+
$error = xml_error_string($code);
18+
echo "xml_parse returned $success, xml_get_error_code = $code, xml_error_string = $error\r\n";
19+
$success = xml_parse($parser, 'Y>', true);
20+
$code = xml_get_error_code($parser);
21+
$error = xml_error_string($code);
22+
echo "xml_parse returned $success, xml_get_error_code = $code, xml_error_string = $error\r\n";
23+
?>
24+
--EXPECT--
25+
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = No error
26+
xml_parse returned 0, xml_get_error_code = 5, xml_error_string = Invalid document end

ext/xml/xml.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,10 @@ PHP_FUNCTION(xml_parse)
12501250
}
12511251

12521252
parser = Z_XMLPARSER_P(pind);
1253+
if (parser->isparsing) {
1254+
php_error_docref(NULL, E_WARNING, "Parser must not be called recursively");
1255+
RETURN_FALSE;
1256+
}
12531257
parser->isparsing = 1;
12541258
ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, isFinal);
12551259
parser->isparsing = 0;
@@ -1297,6 +1301,10 @@ PHP_FUNCTION(xml_parse_into_struct)
12971301
XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
12981302
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
12991303

1304+
if (parser->isparsing) {
1305+
php_error_docref(NULL, E_WARNING, "Parser must not be called recursively");
1306+
RETURN_FALSE;
1307+
}
13001308
parser->isparsing = 1;
13011309
ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, 1);
13021310
parser->isparsing = 0;

0 commit comments

Comments
 (0)