From 4792f7af1cec5e4f00ea2f4025fed54a1a7ee51d Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Mon, 24 Apr 2017 17:53:29 +0100 Subject: [PATCH] Test expanding a param entity's string pool with a failing allocator --- expat/tests/runtests.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index e0349a39..dedaa587 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -7799,6 +7799,53 @@ START_TEST(test_alloc_nested_entities) } END_TEST +START_TEST(test_alloc_realloc_param_entity_newline) +{ + const char *text = + "\n" + ""; + char dtd_text[] = + "\n'>" + "%pe;\n"; + int i; +#define MAX_REALLOC_COUNT 5 + + for (i = 0; i < MAX_REALLOC_COUNT; i++) { + reallocation_count = i; + XML_SetUserData(parser, dtd_text); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(parser, external_entity_alloc); + if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), + XML_TRUE) != XML_STATUS_ERROR) + break; + XML_ParserReset(parser, NULL); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == MAX_REALLOC_COUNT) + fail("Parse failed at maximum reallocation count"); +} +#undef MAX_REALLOC_COUNT +END_TEST + static void nsalloc_setup(void) { @@ -8610,6 +8657,7 @@ make_suite(void) tcase_add_test(tc_alloc, test_alloc_long_attr_default_with_char_ref); tcase_add_test(tc_alloc, test_alloc_long_attr_value); tcase_add_test(tc_alloc, test_alloc_nested_entities); + tcase_add_test(tc_alloc, test_alloc_realloc_param_entity_newline); suite_add_tcase(s, tc_nsalloc); tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown); -- 2.49.0