Test long root element name with a failing allocator

This commit is contained in:
Rhodri James 2017-04-27 14:15:58 +01:00 committed by Sebastian Pipping
parent 96afb81e9a
commit 02a9d765d6

View File

@ -8035,6 +8035,52 @@ START_TEST(test_alloc_realloc_attributes)
#undef MAX_REALLOC_COUNT
END_TEST
START_TEST(test_alloc_long_doc_name)
{
const char *text =
/* 64 characters per line */
"<LongRootElementNameThatWillCauseTheNextAllocationToExpandTheStr"
"ingPoolForTheDTDQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ"
" a='1'/>";
int i;
#define MAX_ALLOC_COUNT 10
int repeat = 0;
for (i = 0; i < MAX_ALLOC_COUNT; i++) {
/* Repeat certain counts to defeat cached allocations */
if ((i == 2 && repeat < 4) ||
(i == 3 && repeat < 6)) {
i--;
repeat++;
}
allocation_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("Parsing worked despite failing reallocations");
else if (i == MAX_ALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
}
#undef MAX_ALLOC_COUNT
END_TEST
static void
nsalloc_setup(void)
@ -9008,6 +9054,7 @@ make_suite(void)
tcase_add_test(tc_alloc, test_alloc_realloc_param_entity_newline);
tcase_add_test(tc_alloc, test_alloc_realloc_ce_extends_pe);
tcase_add_test(tc_alloc, test_alloc_realloc_attributes);
tcase_add_test(tc_alloc, test_alloc_long_doc_name);
suite_add_tcase(s, tc_nsalloc);
tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown);