Projects
openEuler:24.03:SP1:Everything
expat
_service:tar_scm:backport-007-CVE-2023-52425.patch
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:backport-007-CVE-2023-52425.patch of Package expat
From 1d784ef14933ee775fc20ba4435b8def6b70eae3 Mon Sep 17 00:00:00 2001 From: caixiaomeng 00662745 <caixiaomeng2@huawei.com> Date: Mon, 4 Mar 2024 11:00:25 +0800 Subject: [PATCH] tests: Adapat test default current cases for 2.4.1 Reference: https://github.com/libexpat/libexpat/commit/7474fe3d3f686a4d76f1df48c5db0eced295059b Conflict: yes --- tests/runtests.c | 303 +++++++++++++++++++++++++++++++---------- 1 file changed, 234 insertions(+), 69 deletions(-) diff --git a/tests/runtests.c b/tests/runtests.c index c0aa1773..e97a7c51 100644 --- a/tests/runtests.c +++ b/tests/runtests.c @@ -2536,34 +2536,75 @@ START_TEST(test_memory_allocation) { } END_TEST +/* Handlers that record their arg and a single identifying character */ + +struct handler_record_entry { + const char *name; + int arg; +}; +struct handler_record_list { + int count; + struct handler_record_entry entries[50]; // arbitrary big-enough max count +}; + +# define handler_record_get(storage, index) \ + _handler_record_get((storage), (index), __FILE__, __LINE__) + +# define assert_record_handler_called(storage, index, expected_name, \ + expected_arg) \ + do { \ + const struct handler_record_entry *e \ + = handler_record_get(storage, index); \ + assert(strcmp(e->name, expected_name) == 0); \ + assert(e->arg == (expected_arg)); \ + } while (0) + +/* Handlers that record their function name and int arg. */ + +static void +record_call(struct handler_record_list *const rec, const char *funcname, + const int arg) { + const int max_entries = sizeof(rec->entries) / sizeof(rec->entries[0]); + assert(rec->count < max_entries); + struct handler_record_entry *const e = &rec->entries[rec->count++]; + e->name = funcname; + e->arg = arg; +} + static void XMLCALL record_default_handler(void *userData, const XML_Char *s, int len) { UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("D"), 1); + record_call((struct handler_record_list *)userData, __func__, len); } static void XMLCALL record_cdata_handler(void *userData, const XML_Char *s, int len) { UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("C"), 1); + record_call((struct handler_record_list *)userData, __func__, len); XML_DefaultCurrent(g_parser); } static void XMLCALL record_cdata_nodefault_handler(void *userData, const XML_Char *s, int len) { UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("c"), 1); + record_call((struct handler_record_list *)userData, __func__, len); } static void XMLCALL record_skip_handler(void *userData, const XML_Char *entityName, int is_parameter_entity) { UNUSED_P(entityName); - CharData_AppendXMLChars((CharData *)userData, - is_parameter_entity ? XCS("E") : XCS("e"), 1); + record_call((struct handler_record_list *)userData, __func__, + is_parameter_entity); +} + +static const struct handler_record_entry * +_handler_record_get(const struct handler_record_list *storage, int index, + const char *file, int line) { + if (storage->count <= index) { + fail("too few handler calls"); + } + return &storage->entries[index]; } /* Test XML_DefaultCurrent() passes handling on correctly */ @@ -2573,78 +2614,202 @@ START_TEST(test_default_current) { "<!ENTITY entity '%'>\n" "]>\n" "<doc>&entity;</doc>"; - CharData storage; - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DCDCDCDCDCDD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + int i = 0; + assert_record_handler_called(&storage, i++, "record_default_handler", 5); + // we should have gotten one or more cdata callbacks, totaling 5 chars + int cdata_len_remaining = 5; + while (cdata_len_remaining > 0) { + const struct handler_record_entry *c_entry + = handler_record_get(&storage, i++); + assert(strcmp(c_entry->name, "record_cdata_handler") == 0); + assert(c_entry->arg > 0); + assert(c_entry->arg <= cdata_len_remaining); + cdata_len_remaining -= c_entry->arg; + // default handler must follow, with the exact same len argument. + assert_record_handler_called(&storage, i++, "record_default_handler", + c_entry->arg); + } + assert_record_handler_called(&storage, i++, "record_default_handler", 6); + assert(storage.count == i); + } /* Again, without the defaulting */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DcccccD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + int i = 0; + assert_record_handler_called(&storage, i++, "record_default_handler", 5); + // we should have gotten one or more cdata callbacks, totaling 5 chars + int cdata_len_remaining = 5; + while (cdata_len_remaining > 0) { + const struct handler_record_entry *c_entry + = handler_record_get(&storage, i++); + assert(strcmp(c_entry->name, "record_cdata_nodefault_handler") == 0); + assert(c_entry->arg > 0); + assert(c_entry->arg <= cdata_len_remaining); + cdata_len_remaining -= c_entry->arg; + } + assert_record_handler_called(&storage, i++, "record_default_handler", 6); + assert(storage.count == i); + } /* Now with an internal entity to complicate matters */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* The default handler suppresses the entity */ - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDDD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* The default handler suppresses the entity */ + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_default_handler", 8); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert(storage.count == 19); + } /* Again, with a skip handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - XML_SetSkippedEntityHandler(g_parser, record_skip_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* The default handler suppresses the entity */ - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDeD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetSkippedEntityHandler(g_parser, record_skip_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* The default handler suppresses the entity */ + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_skip_handler", 0); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert(storage.count == 19); + } /* This time, allow the entity through */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandlerExpand(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDCDD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandlerExpand(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_cdata_handler", 1); + assert_record_handler_called(&storage, 18, "record_default_handler", 1); + assert_record_handler_called(&storage, 19, "record_default_handler", 6); + assert(storage.count == 20); + } /* Finally, without passing the cdata to the default handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandlerExpand(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDcD")); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandlerExpand(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_cdata_nodefault_handler", + 1); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert(storage.count == 19); + } } END_TEST -- 2.33.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2