From ee4581af4134958d05b85562d9bb60e1e48968f6 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 31 Jul 2019 20:41:24 +0200 Subject: [PATCH] runtests.c: Add two test cases for/from issue #240 Many thanks to Rolf Ade (@pointsman)! --- expat/Changes | 1 + expat/tests/runtests.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/expat/Changes b/expat/Changes index 5085865c..3c18c6ac 100644 --- a/expat/Changes +++ b/expat/Changes @@ -23,6 +23,7 @@ Release x.x.x xxx xxx xx xxxx Khajapasha Mohammed Kishore Kunche Marco Maggi + Rolf Ade xantares Release 2.2.7 Wed June 19 2019 diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 60710c83..c3f65bea 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -7259,6 +7259,69 @@ START_TEST(test_misc_utf16le) { } END_TEST +typedef struct { + XML_Parser parser; + int deep; +} DataIssue240; + +static void +start_element_issue_240(void *userData, const XML_Char *UNUSED_P(name), + const XML_Char **UNUSED_P(atts)) { + DataIssue240 *mydata = (DataIssue240 *)userData; + mydata->deep++; +} + +static void +end_element_issue_240(void *userData, const XML_Char *UNUSED_P(name)) { + DataIssue240 *mydata = (DataIssue240 *)userData; + mydata->deep--; + if (mydata->deep == 0) { + XML_StopParser(mydata->parser, 0); + } +} + +START_TEST(test_misc_stop_during_end_handler_issue_240_1) { + XML_Parser parser; + DataIssue240 *mydata; + enum XML_Status result; + const char *const doc1 = ""; + + parser = XML_ParserCreate(NULL); + XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); + mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); + mydata->parser = parser; + mydata->deep = 0; + XML_SetUserData(parser, mydata); + + result = XML_Parse(parser, doc1, (int)strlen(doc1), 1); + XML_ParserFree(parser); + free(mydata); + if (result != XML_STATUS_ERROR) + fail("Stopping the parser did not work as expected"); +} +END_TEST + +START_TEST(test_misc_stop_during_end_handler_issue_240_2) { + XML_Parser parser; + DataIssue240 *mydata; + enum XML_Status result; + const char *const doc2 = ""; + + parser = XML_ParserCreate(NULL); + XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); + mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); + mydata->parser = parser; + mydata->deep = 0; + XML_SetUserData(parser, mydata); + + result = XML_Parse(parser, doc2, (int)strlen(doc2), 1); + XML_ParserFree(parser); + free(mydata); + if (result != XML_STATUS_ERROR) + fail("Stopping the parser did not work as expected"); +} +END_TEST + static void alloc_setup(void) { XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; @@ -11170,6 +11233,8 @@ make_suite(void) { tcase_add_test(tc_misc, test_misc_features); tcase_add_test(tc_misc, test_misc_attribute_leak); tcase_add_test(tc_misc, test_misc_utf16le); + tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_1); + tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_2); suite_add_tcase(s, tc_alloc); tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown);