2
0
Эх сурвалжийг харах

Added sanity checks to xacro preventing crash. (#324)

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 2 жил өмнө
parent
commit
753adf784e

+ 4 - 0
Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp

@@ -321,6 +321,10 @@ namespace ROS2
                     return m_checkUrdfPage->nextId();
                     return m_checkUrdfPage->nextId();
                 }
                 }
             }
             }
+            if (m_params.empty())
+            {
+                return m_xacroParamsPage->nextId();
+            }
         }
         }
         return currentPage()->nextId();
         return currentPage()->nextId();
     }
     }

+ 8 - 0
Gems/ROS2/Code/Source/RobotImporter/xacro/XacroUtils.cpp

@@ -94,7 +94,15 @@ namespace ROS2::Utils::xacro
         AZStd::unordered_map<AZStd::string, AZStd::string> params;
         AZStd::unordered_map<AZStd::string, AZStd::string> params;
         AZ::rapidxml::xml_document<char> doc;
         AZ::rapidxml::xml_document<char> doc;
         doc.parse<AZ::rapidxml::parse_full>(dataArray.data());
         doc.parse<AZ::rapidxml::parse_full>(dataArray.data());
+        if (doc.first_node() == nullptr)
+        {
+            return params;
+        }
         AZ::rapidxml::xml_node<char>* xmlRootNode = doc.first_node("robot");
         AZ::rapidxml::xml_node<char>* xmlRootNode = doc.first_node("robot");
+        if (xmlRootNode == nullptr)
+        {
+            return params;
+        }
         for (AZ::rapidxml::xml_node<>* child_node = xmlRootNode->first_node(); child_node; child_node = child_node->next_sibling())
         for (AZ::rapidxml::xml_node<>* child_node = xmlRootNode->first_node(); child_node; child_node = child_node->next_sibling())
         {
         {
             if (strcmp(argNameTag, child_node->name()) == 0)
             if (strcmp(argNameTag, child_node->name()) == 0)

+ 7 - 0
Gems/ROS2/Code/Tests/UrdfParserTest.cpp

@@ -462,6 +462,13 @@ namespace UnitTest
         EXPECT_EQ(result, resolvedDae);
         EXPECT_EQ(result, resolvedDae);
     }
     }
 
 
+    TEST_F(UrdfParserTest, XacroParseArgsInvalid)
+    {
+        AZStd::string xacroParams = GetXacroParams();
+        ROS2::Utils::xacro::Params params = ROS2::Utils::xacro::GetParameterFromXacroData("");
+        EXPECT_EQ(params.size(), 0);
+    }
+
     TEST_F(UrdfParserTest, XacroParseArgs)
     TEST_F(UrdfParserTest, XacroParseArgs)
     {
     {
         AZStd::string xacroParams = GetXacroParams();
         AZStd::string xacroParams = GetXacroParams();