From: Rhodri James Date: Thu, 9 Mar 2017 16:28:47 +0000 (+0000) Subject: Test public doctype with long public name against failing allocator X-Git-Tag: R_2_2_3~22^2~223 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fab38d3fc01ee5998d6bfcfe805af67daff2612c;p=libexpat Test public doctype with long public name against failing allocator --- diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index ed7e9a08..b4567080 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -5884,6 +5884,62 @@ START_TEST(test_alloc_parse_public_doctype) #undef MAX_ALLOC_COUNT END_TEST +START_TEST(test_alloc_parse_public_doctype_long_name) +{ + const char *text = + "\n" + "\n" + ""; + int i; +#define MAX_ALLOC_COUNT 10 + int repeat = 0; + + for (i = 0; i < MAX_ALLOC_COUNT; i++) { + /* Repeat some counts to defeat cached allocations */ + if (i == 4 && repeat == 6) { + i -= 2; + repeat++; + } + else if ((i == 2 && repeat < 3) || + (i == 3 && repeat < 6)) { + i--; + repeat++; + } + allocation_count = i; + XML_SetDoctypeDeclHandler(parser, + dummy_start_doctype_decl_handler, + dummy_end_doctype_decl_handler); + 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 allocator"); + if (i == MAX_ALLOC_COUNT) + fail("Parse failed at maximum allocation count"); +} +#undef MAX_ALLOC_COUNT +END_TEST + static int XMLCALL external_entity_alloc(XML_Parser parser, const XML_Char *context, @@ -6909,6 +6965,7 @@ make_suite(void) tcase_add_test(tc_alloc, test_alloc_realloc_many_attributes); tcase_add_test(tc_alloc, test_alloc_public_entity_value); tcase_add_test(tc_alloc, test_alloc_parse_public_doctype); + tcase_add_test(tc_alloc, test_alloc_parse_public_doctype_long_name); tcase_add_test(tc_alloc, test_alloc_set_foreign_dtd); tcase_add_test(tc_alloc, test_alloc_attribute_enum_value); tcase_add_test(tc_alloc, test_alloc_realloc_attribute_enum_value);