From: Rhodri James Date: Tue, 21 Feb 2017 18:25:41 +0000 (+0000) Subject: Extend test coverage of external entity handler parameters X-Git-Tag: R_2_2_3~28^2~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ade4c402af1d282edb819fbc956ff0bb32ac2c33;p=libexpat Extend test coverage of external entity handler parameters --- diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 0542f9ad..d6a004b6 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -2750,16 +2750,34 @@ END_TEST /* Test that an explicit external entity handler argument replaces * the parser as the first argument. + * + * We do not call the first parameter to the external entity handler + * 'parser' for once, since the first time the handler is called it + * will actually be a text string. We need to be able to access the + * global 'parser' variable to create our external entity parser from, + * since there are code paths we need to ensure get executed. */ static int XMLCALL -external_entity_ref_param_checker(XML_Parser parser, - const XML_Char *UNUSED_P(context), +external_entity_ref_param_checker(XML_Parser parameter, + const XML_Char *context, const XML_Char *UNUSED_P(base), const XML_Char *UNUSED_P(systemId), const XML_Char *UNUSED_P(publicId)) { - if ((void *)parser != handler_data) + const char *text = ""; + XML_Parser ext_parser; + + if ((void *)parameter != handler_data) fail("External entity ref handler parameter not correct"); + + /* Here we use the global 'parser' variable */ + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, strlen(text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(ext_parser); + return XML_STATUS_OK; }