Fix #81351: xml_parse may fail, but has no error code

The fix for bug #73151[1] cured the symptoms, but not the root cause,
namely xmlParse() must not be called recursively.  Since that bugfix
also messed up the error handling, we basically revert it (but also
simplify the return), and then prevent calling the parser recursively.

[1] <f2a8a8c068>

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>

Closes GH-7363.
This commit is contained in:
Christoph M. Becker 2021-08-13 16:09:11 +02:00
parent 78cbe56e68
commit 80a377e69b
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
5 changed files with 44 additions and 9 deletions

View file

@ -1416,6 +1416,10 @@ PHP_FUNCTION(xml_parse)
RETURN_FALSE;
}
if (parser->isparsing) {
php_error_docref(NULL, E_WARNING, "Parser must not be called recursively");
RETURN_FALSE;
}
parser->isparsing = 1;
ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, isFinal);
parser->isparsing = 0;
@ -1467,6 +1471,10 @@ PHP_FUNCTION(xml_parse_into_struct)
XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
if (parser->isparsing) {
php_error_docref(NULL, E_WARNING, "Parser must not be called recursively");
RETURN_FALSE;
}
parser->isparsing = 1;
ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, 1);
parser->isparsing = 0;