]> granicus.if.org Git - libexpat/commitdiff
Extend test coverage of external entity handler parameters
authorRhodri James <rhodri@kynesim.co.uk>
Tue, 21 Feb 2017 18:25:41 +0000 (18:25 +0000)
committerSebastian Pipping <sebastian@pipping.org>
Sun, 16 Jul 2017 16:56:24 +0000 (18:56 +0200)
expat/tests/runtests.c

index 0542f9ad3b81928a48e9448356c9176cd95fc881..d6a004b683c5f4f67110d7cbeda87731a66adca0 100644 (file)
@@ -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 = "<!ELEMENT doc (#PCDATA)*>";
+    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;
 }