From a907798a0979513e1bb71a8374ba1b1c98332c95 Mon Sep 17 00:00:00 2001 From: elianalf <62831776+elianalf@users.noreply.github.com> Date: Thu, 29 Feb 2024 08:10:08 +0100 Subject: [PATCH] Add catch of out-of-range exception for thread settings port (#4461) * Refs #20187: Add catch of out-of-range exception for thread settings port Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com> * Refs #20187: Uncrustify Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com> --------- Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com> --- src/cpp/rtps/xmlparser/XMLElementParser.cpp | 8 ++++++++ test/unittest/xmlparser/XMLParserTests.cpp | 1 + test/unittest/xmlparser/regressions/20187_profile_bin.xml | 1 + 3 files changed, 10 insertions(+) create mode 100644 test/unittest/xmlparser/regressions/20187_profile_bin.xml diff --git a/src/cpp/rtps/xmlparser/XMLElementParser.cpp b/src/cpp/rtps/xmlparser/XMLElementParser.cpp index 18f1fad219e..093d379b253 100644 --- a/src/cpp/rtps/xmlparser/XMLElementParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLElementParser.cpp @@ -4579,6 +4579,14 @@ XMLP_ret XMLParser::getXMLThreadSettingsWithPort( ret = XMLP_ret::XML_ERROR; break; } + catch (const std::out_of_range& except) + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Value of the port attribute " << attrib->Value() << " out of range. " << + except.what()); + ret = XMLP_ret::XML_ERROR; + break; + } } else { diff --git a/test/unittest/xmlparser/XMLParserTests.cpp b/test/unittest/xmlparser/XMLParserTests.cpp index 78999d600f2..a0454e0c4a6 100644 --- a/test/unittest/xmlparser/XMLParserTests.cpp +++ b/test/unittest/xmlparser/XMLParserTests.cpp @@ -71,6 +71,7 @@ TEST_F(XMLParserTests, regressions) 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)); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/20186_profile_bin.xml", root)); + EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/20187_profile_bin.xml", root)); } TEST_F(XMLParserTests, NoFile) diff --git a/test/unittest/xmlparser/regressions/20187_profile_bin.xml b/test/unittest/xmlparser/regressions/20187_profile_bin.xml new file mode 100644 index 00000000000..0024e17ed6d --- /dev/null +++ b/test/unittest/xmlparser/regressions/20187_profile_bin.xml @@ -0,0 +1 @@ +