From 41ab4fd94ad1ef48f0fb5272f5ee0eb5b4ec24f2 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 17 Feb 2017 16:21:17 +0000 Subject: [PATCH] Test reallocation failure in xmlns attribute handling Note that this commit provokes a segfault due to a bug in storeAtts() --- expat/tests/runtests.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index e007bdae..1011510e 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -4505,6 +4505,32 @@ START_TEST(test_nsalloc_long_prefix) #undef MAX_ALLOC_COUNT END_TEST +/* Test attribute handling in the face of a dodgy reallocator */ +START_TEST(test_nsalloc_realloc_attributes) +{ + const char *text = + "" + ""; + 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("Parsing worked despite failing reallocations"); + else if (i == MAX_REALLOC_COUNT) + fail("Parsing failed at max reallocation count"); +} +#undef MAX_REALLOC_COUNT +END_TEST + + static Suite * make_suite(void) { @@ -4652,6 +4678,7 @@ make_suite(void) tcase_add_test(tc_nsalloc, test_nsalloc_xmlns); tcase_add_test(tc_nsalloc, test_nsalloc_parse_buffer); tcase_add_test(tc_nsalloc, test_nsalloc_long_prefix); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_attributes); return s; }