From 02dfd4b377aa4cc7cec8f6de3c01109e987738ca Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 17 Mar 2017 16:40:52 +0000 Subject: [PATCH] Test long attribute with a dodgy reallocator This tests a specific code path through parameter substitution, and requires the attribute value to come out to 1024 bytes PLUS a terminal NUL to trigger growth of the string pool in use. The NUL is added separately, and it is that string append that we are triggering on. --- expat/tests/runtests.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index a0fb5928..397f1c43 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -7306,6 +7306,47 @@ START_TEST(test_alloc_comment_in_epilog) #undef MAX_ALLOC_COUNT END_TEST +START_TEST(test_alloc_realloc_long_attribute_value) +{ + const char *text = + "]>\n" + ""; + int i; +#define MAX_REALLOC_COUNT 10 + + for (i = 0; i < MAX_REALLOC_COUNT; i++) { + reallocation_count = i; + 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) @@ -8104,6 +8145,7 @@ make_suite(void) tcase_add_test(tc_alloc, test_alloc_realloc_group_choice); tcase_add_test(tc_alloc, test_alloc_pi_in_epilog); tcase_add_test(tc_alloc, test_alloc_comment_in_epilog); + tcase_add_test(tc_alloc, test_alloc_realloc_long_attribute_value); suite_add_tcase(s, tc_nsalloc); tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown); -- 2.40.0