From b03edfd9615aecd766b1ecbb2495600e1ec015ec Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Wed, 3 May 2017 18:06:54 +0100 Subject: [PATCH] Test with long default attribute for ext parser with duff allocator --- expat/tests/runtests.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 2b6abac5..2c9ad581 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -9587,6 +9587,71 @@ START_TEST(test_nsalloc_realloc_long_context_in_dtd) } END_TEST +START_TEST(test_nsalloc_long_default_in_ext) +{ + const char *text = + "\n" + " \n" + "]>\n" + "&x;"; + ExtOption options[] = { + { "foo", ""}, + { NULL, NULL } + }; + int i; +#define MAX_ALLOC_COUNT 30 + int repeat = 0; + + for (i = 0; i < MAX_ALLOC_COUNT; i++) { + /* Repeat some counts to defeat allocation caching */ + if ((i == 4 && repeat == 3) || (i == 8 && repeat == 9)) { + i -= 2; + repeat++; + } + else if ((i == 2 && repeat < 2) || + (i == 3 && (repeat == 2 || repeat == 4 || repeat == 5)) || + (i == 4 && repeat == 6) || + (i == 5 && repeat == 7) || + (i == 6 && repeat == 8)) { + i--; + repeat++; + } + allocation_count = i; + XML_SetUserData(parser, options); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(parser, external_entity_optioner); + 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 allocations"); + else if (i == MAX_ALLOC_COUNT) + fail("Parsing failed even at max allocation count"); +#undef MAX_ALLOC_COUNT +} +END_TEST + static Suite * make_suite(void) @@ -9851,6 +9916,7 @@ make_suite(void) tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_7); tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_ge_name); tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_in_dtd); + tcase_add_test(tc_nsalloc, test_nsalloc_long_default_in_ext); return s; }