Test allocation failures during external entity parsing
@@ -1690,6 +1690,55 @@ START_TEST(test_alloc_create_external_parser)
}
END_TEST
+static int XMLCALL
+external_entity_null_loader(XML_Parser UNUSED_P(parser),
+ const XML_Char *UNUSED_P(context),
+ const XML_Char *UNUSED_P(base),
+ const XML_Char *UNUSED_P(systemId),
+ const XML_Char *UNUSED_P(publicId))
+{
+ return XML_STATUS_OK;
+}
+
+/* More external parser memory allocation testing */
+START_TEST(test_alloc_run_external_parser)
+{
+ const char *text =
+ "<?xml version='1.0' encoding='us-ascii'?>\n"
+ "<!DOCTYPE doc SYSTEM 'foo'>\n"
+ "<doc>&entity;</doc>";
+ char foo_text[] =
+ "<!ELEMENT doc (#PCDATA)*>";
+ XML_Memory_Handling_Suite memsuite = { duff_allocator, realloc, free };
+ unsigned int i;
+
+ /* Ensure the initial memory allocations go through */
+ allocation_count = 10000;
+ parser = XML_ParserCreate_MM(NULL, &memsuite, NULL);
+ if (parser == NULL) {
+ fail("Failed to create parser");
+ } else {
+ for (i = 0; i < 10; i++) {
+ XML_SetParamEntityParsing(parser,
+ XML_PARAM_ENTITY_PARSING_ALWAYS);
+ XML_SetUserData(parser, foo_text);
+ XML_SetExternalEntityRefHandler(parser,
+ external_entity_null_loader);
+ allocation_count = i;
+ if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR)
+ break;
+ /* Re-use the parser */
+ XML_ParserReset(parser, NULL);
+ }
+ if (i == 0)
+ fail("Parsing ignored failing allocator");
+ else if (i == 10)
+ fail("Parsing failed with allocation count 10");
+ }
+}
+END_TEST
+
+
static int XMLCALL
external_entity_dbl_handler(XML_Parser parser,
const XML_Char *context,
@@ -1855,6 +1904,7 @@ make_suite(void)
tcase_add_checked_fixture(tc_alloc, NULL, basic_teardown);
tcase_add_test(tc_alloc, test_alloc_create_parser);
tcase_add_test(tc_alloc, test_alloc_create_external_parser);
+ tcase_add_test(tc_alloc, test_alloc_run_external_parser);
tcase_add_test(tc_alloc, test_alloc_dtd_copy_default_atts);
return s;
