Skip to content

Commit

Permalink
Fix missing mandatory attribute check in XML parser struct type (#3995)
Browse files Browse the repository at this point in the history
* Refs #19851: Fix missing mandatory attribute check

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #19851: Apply rev suggestions

Signed-off-by: JesusPoderoso <[email protected]>

---------

Signed-off-by: JesusPoderoso <[email protected]>
(cherry picked from commit b10bfe6)
  • Loading branch information
JesusPoderoso committed Nov 13, 2023
1 parent 8d0b35a commit 6a08b79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cpp/rtps/xmlparser/XMLDynamicParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ XMLP_ret XMLParser::parseXMLStructDynamicType(
*/
XMLP_ret ret = XMLP_ret::XML_OK;
const char* name = p_root->Attribute(NAME);
if (nullptr == name || name[0] == '\0')
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Missing required attribute 'name' in 'structDcl'.");
return XMLP_ret::XML_ERROR;
}

p_dynamictypebuilder_t typeBuilder; // = types::DynamicTypeBuilderFactory::get_instance()->create_struct_builder();
//typeBuilder->set_name(name);
uint32_t mId = 0;
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/XMLParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ TEST_F(XMLParserTests, regressions)
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/18395_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/19354_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/19354_2_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/19851_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/simple_participant_profiles_nok.xml", root));
EXPECT_EQ(XMLP_ret::XML_OK, XMLParser::loadXML("regressions/simple_participant_profiles_ok.xml", root));
}
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xmlparser/regressions/19851_profile_bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<types><type><struct/></type></types>

0 comments on commit 6a08b79

Please sign in to comment.