From 8413fc9ac7e29fd0978dc519ecc4b2246c268678 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Thu, 30 May 2024 09:54:10 +0200 Subject: [PATCH] Refs #21054: Add checks for repeated tags and test Signed-off-by: Mario Dominguez --- src/cpp/xmlparser/XMLElementParser.cpp | 12 ++++++++++++ test/unittest/xmlparser/XMLElementParserTests.cpp | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cpp/xmlparser/XMLElementParser.cpp b/src/cpp/xmlparser/XMLElementParser.cpp index 53642066576..d89387ccfd7 100644 --- a/src/cpp/xmlparser/XMLElementParser.cpp +++ b/src/cpp/xmlparser/XMLElementParser.cpp @@ -938,6 +938,7 @@ XMLP_ret XMLParser::getXMLFlowControllerDescriptorList( tinyxml2::XMLElement* p_aux1; bool name_defined = false; + std::set tags_present; auto flow_controller_descriptor = std::make_shared(); @@ -945,6 +946,17 @@ XMLP_ret XMLParser::getXMLFlowControllerDescriptorList( { const char* name = p_aux1->Name(); + if (tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Duplicated element found in 'flowControllerDescriptorType'. Name: " << name); + return XMLP_ret::XML_ERROR; + } + else + { + tags_present.emplace(name); + } + if (strcmp(name, NAME) == 0) { // name - stringType diff --git a/test/unittest/xmlparser/XMLElementParserTests.cpp b/test/unittest/xmlparser/XMLElementParserTests.cpp index b3e57f5a00c..61ba62230db 100644 --- a/test/unittest/xmlparser/XMLElementParserTests.cpp +++ b/test/unittest/xmlparser/XMLElementParserTests.cpp @@ -2113,7 +2113,18 @@ TEST_F(XMLParserTests, getXMLFlowControllerDescriptorList) {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ "12", "12", "12", "12", "" }, XMLP_ret::XML_ERROR}, // Invalid tag {{"", "HIGH_PRIORITY", "120", "50", \ - "12", "12", "12", "12", "" }, XMLP_ret::XML_ERROR}, // empty name + "12", "12", "12", "12", "" }, XMLP_ret::XML_ERROR}, // empty name + {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ + "12", "12", "12", "12", "another_name" }, XMLP_ret::XML_ERROR}, // duplicated name tag + {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ + "12", "12", "12", "12", "FIFO" }, XMLP_ret::XML_ERROR}, // duplicated scheduler tag + {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ + "12", "12", "12", "12", "96" }, XMLP_ret::XML_ERROR}, // duplicated max_bytes_per_period tag + {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ + "12", "12", "12", "12", "96" }, XMLP_ret::XML_ERROR}, // duplicated period_ms tag + {{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \ + "12", "12", "12", "12", "12" }, + XMLP_ret::XML_ERROR}, // duplicated sender_thread tag {{"", "HIGH_PRIORITY", "120", "50", \ "12345", "12", "12", "a", "" }, XMLP_ret::XML_ERROR}, // invalid thread settings };