From 5f124f4e7cd34359f5a7cfa43d0289c67d7cf6f4 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Thu, 9 Mar 2017 14:46:44 +0000 Subject: [PATCH] Test attribute with implied large enum with a failing reallocator --- expat/tests/runtests.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 840a0335..4c451803 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -6038,6 +6038,55 @@ START_TEST(test_alloc_realloc_attribute_enum_value) #undef MAX_REALLOC_COUNT END_TEST +/* Test attribute enums in a #IMPLIED attribute forcing pool growth */ +START_TEST(test_alloc_realloc_implied_attribute) +{ + /* Forcing this particular code path is a balancing act. The + * addition of the closing parenthesis and terminal NUL must be + * what pushes the string of enums over the 1024-byte limit, + * otherwise a different code path will pick up the realloc. + */ + const char *text = + "\n" + "\n" + "]>"; + int i; +#define MAX_REALLOC_COUNT 10 + for (i = 0; i < MAX_REALLOC_COUNT; i++) { + reallocation_count = i; + XML_SetAttlistDeclHandler(parser, dummy_attlist_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 reallocator"); + if (i == MAX_REALLOC_COUNT) + fail("Parse failed at maximum reallocation count"); +} +#undef MAX_REALLOC_COUNT +END_TEST + static void nsalloc_setup(void) @@ -6803,6 +6852,7 @@ make_suite(void) 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); + tcase_add_test(tc_alloc, test_alloc_realloc_implied_attribute); suite_add_tcase(s, tc_nsalloc); tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown); -- 2.49.0