Refactor context URI reallocation tests

This commit is contained in:
Rhodri James 2017-04-28 18:18:29 +01:00 committed by Sebastian Pipping
parent ae9fe3c614
commit 67f238b794

View File

@ -9073,6 +9073,37 @@ external_entity_optioner(XML_Parser parser,
return XML_STATUS_ERROR; return XML_STATUS_ERROR;
} }
/* This function is void; it will throw a fail() on error, so if it
* returns normally it must have succeeded.
*/
static void
context_realloc_test(XML_Parser parser, const char *text)
{
ExtOption options[] = {
{ "foo", "<!ELEMENT e EMPTY>"},
{ "bar", "<e/>" },
{ NULL, NULL }
};
int i;
#define MAX_REALLOC_COUNT 5
for (i = 0; i < MAX_REALLOC_COUNT; i++) {
reallocation_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 reallocations");
else if (i == MAX_REALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
#undef MAX_REALLOC_COUNT
}
START_TEST(test_nsalloc_realloc_long_context) START_TEST(test_nsalloc_realloc_long_context)
{ {
const char *text = const char *text =
@ -9100,30 +9131,9 @@ START_TEST(test_nsalloc_realloc_long_context)
"'>\n" "'>\n"
"&en;" "&en;"
"</doc>"; "</doc>";
ExtOption options[] = {
{ "foo", "<!ELEMENT e EMPTY>"},
{ "bar", "<e/>" },
{ NULL, NULL }
};
int i;
#define MAX_REALLOC_COUNT 5
for (i = 0; i < MAX_REALLOC_COUNT; i++) { context_realloc_test(parser, text);
reallocation_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 reallocations");
else if (i == MAX_REALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
} }
#undef MAX_REALLOC_COUNT
END_TEST END_TEST
START_TEST(test_nsalloc_realloc_long_context_2) START_TEST(test_nsalloc_realloc_long_context_2)
@ -9153,30 +9163,9 @@ START_TEST(test_nsalloc_realloc_long_context_2)
"'>\n" "'>\n"
"&en;" "&en;"
"</doc>"; "</doc>";
ExtOption options[] = {
{ "foo", "<!ELEMENT e EMPTY>"},
{ "bar", "<e/>" },
{ NULL, NULL }
};
int i;
#define MAX_REALLOC_COUNT 5
for (i = 0; i < MAX_REALLOC_COUNT; i++) { context_realloc_test(parser, text);
reallocation_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 reallocations");
else if (i == MAX_REALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
} }
#undef MAX_REALLOC_COUNT
END_TEST END_TEST
START_TEST(test_nsalloc_realloc_long_context_3) START_TEST(test_nsalloc_realloc_long_context_3)
@ -9206,30 +9195,9 @@ START_TEST(test_nsalloc_realloc_long_context_3)
"'>\n" "'>\n"
"&en;" "&en;"
"</doc>"; "</doc>";
ExtOption options[] = {
{ "foo", "<!ELEMENT e EMPTY>"},
{ "bar", "<e/>" },
{ NULL, NULL }
};
int i;
#define MAX_REALLOC_COUNT 5
for (i = 0; i < MAX_REALLOC_COUNT; i++) { context_realloc_test(parser, text);
reallocation_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 reallocations");
else if (i == MAX_REALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
} }
#undef MAX_REALLOC_COUNT
END_TEST END_TEST
START_TEST(test_nsalloc_realloc_long_context_4) START_TEST(test_nsalloc_realloc_long_context_4)
@ -9259,30 +9227,9 @@ START_TEST(test_nsalloc_realloc_long_context_4)
"'>\n" "'>\n"
"&en;" "&en;"
"</doc>"; "</doc>";
ExtOption options[] = {
{ "foo", "<!ELEMENT e EMPTY>"},
{ "bar", "<e/>" },
{ NULL, NULL }
};
int i;
#define MAX_REALLOC_COUNT 5
for (i = 0; i < MAX_REALLOC_COUNT; i++) { context_realloc_test(parser, text);
reallocation_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 reallocations");
else if (i == MAX_REALLOC_COUNT)
fail("Parsing failed even at max reallocation count");
} }
#undef MAX_REALLOC_COUNT
END_TEST END_TEST