Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #5388 Whitelist parsing checks. [5393] #530

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/fastrtps/xmlparser/XMLProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class XMLProfileManager
m_publisher_profiles.clear();
m_subscriber_profiles.clear();
m_xml_files.clear();
m_transport_profiles.clear();

for (auto pair : m_dynamictypes)
{
Expand Down
64 changes: 37 additions & 27 deletions src/cpp/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ XMLP_ret XMLParser::parseXMLCommonTransportData(tinyxml2::XMLElement* p_root, sp
<xs:element name="TTL" type="uint8Type" minOccurs="0" maxOccurs="1"/>
<xs:element name="maxMessageSize" type="uint32Type" minOccurs="0" maxOccurs="1"/>
<xs:element name="maxInitialPeersRange" type="uint32Type" minOccurs="0" maxOccurs="1"/>
<xs:element name="interfaceWhiteList" type="stringListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="interfaceWhiteList" type="addressListType" minOccurs="0" maxOccurs="1"/>
<xs:element name="wan_addr" type="stringType" minOccurs="0" maxOccurs="1"/>
<xs:element name="output_port" type="uint16Type" minOccurs="0" maxOccurs="1"/>
<xs:element name="keep_alive_frequency_ms" type="uint32Type" minOccurs="0" maxOccurs="1"/>
Expand All @@ -397,26 +397,27 @@ XMLP_ret XMLParser::parseXMLCommonTransportData(tinyxml2::XMLElement* p_root, sp
</xs:complexType>
*/

std::shared_ptr<rtps::SocketTransportDescriptor> pDesc = std::dynamic_pointer_cast<rtps::SocketTransportDescriptor>(p_transport);
std::shared_ptr<rtps::SocketTransportDescriptor> pDesc =
std::dynamic_pointer_cast<rtps::SocketTransportDescriptor>(p_transport);

tinyxml2::XMLElement *p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, SEND_BUFFER_SIZE) == 0)
{
// sendBufferSize - int32Type
int iSize = 0;
if (XMLP_ret::XML_OK != getXMLInt(p_aux0, &iSize, 0) || iSize < 0)
uint32_t iSize = 0;
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &iSize, 0))
return XMLP_ret::XML_ERROR;
pDesc->sendBufferSize = iSize;
}
else if (strcmp(name, RECEIVE_BUFFER_SIZE) == 0)
{
// receiveBufferSize - int32Type
int iSize = 0;
if (XMLP_ret::XML_OK != getXMLInt(p_aux0, &iSize, 0) || iSize < 0)
uint32_t iSize = 0;
if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &iSize, 0))
return XMLP_ret::XML_ERROR;
pDesc->receiveBufferSize = iSize;
}
Expand Down Expand Up @@ -446,16 +447,25 @@ XMLP_ret XMLParser::parseXMLCommonTransportData(tinyxml2::XMLElement* p_root, sp
}
else if (strcmp(name, WHITE_LIST) == 0)
{
// InterfaceWhiteList stringListType
tinyxml2::XMLElement* p_aux1 = p_aux0->FirstChildElement(ADDRESS);
while (nullptr != p_aux1)
// InterfaceWhiteList addressListType
const char* address = nullptr;
for (tinyxml2::XMLElement* p_aux1 = p_aux0->FirstChildElement();
p_aux1 != nullptr; p_aux1 = p_aux1->NextSiblingElement())
{
const char* text = p_aux1->GetText();
if (nullptr != text)
address = p_aux1->Name();
if (strcmp(address, ADDRESS) == 0)
{
pDesc->interfaceWhiteList.emplace_back(text);
const char* text = p_aux1->GetText();
if (nullptr != text)
{
pDesc->interfaceWhiteList.emplace_back(text);
}
}
else
{
logError(XMLPARSER, "Invalid element found into 'interfaceWhiteList'. Name: " << address);
return XMLP_ret::XML_ERROR;
}
p_aux1 = p_aux1->NextSiblingElement(ADDRESS);
}
}
else if (strcmp(name, TCP_WAN_ADDR) == 0 || strcmp(name, UDP_OUTPUT_PORT) == 0 ||
Expand Down Expand Up @@ -508,7 +518,7 @@ XMLP_ret XMLParser::parseXMLCommonTCPTransportData(tinyxml2::XMLElement* p_root,
{
tinyxml2::XMLElement *p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, KEEP_ALIVE_FREQUENCY) == 0)
Expand Down Expand Up @@ -1162,7 +1172,7 @@ XMLP_ret XMLParser::parseXMLAliasDynamicType(tinyxml2::XMLElement* p_root)
const char* boundStr = p_root->Attribute(STR_MAXLENGTH);
if (boundStr != nullptr)
{
bound = std::atoi(boundStr);
bound = static_cast<uint32_t>(std::atoi(boundStr));
}
valueBuilder = getDiscriminatorTypeBuilder(type, bound);
}
Expand Down Expand Up @@ -1539,7 +1549,7 @@ XMLP_ret XMLParser::parseXMLEnumDynamicType(tinyxml2::XMLElement* p_root)
const char* value = literal->Attribute(VALUE);
if (value != nullptr)
{
currValue = std::atoi(value);
currValue = static_cast<uint32_t>(std::atoi(value));
}
typeBuilder->add_empty_member(currValue++, name);
}
Expand Down Expand Up @@ -1720,7 +1730,7 @@ static void dimensionsToArrayBounds(const std::string& dimensions, std::vector<u

while (std::getline(ss, item, ','))
{
bounds.push_back(std::atoi(item.c_str()));
bounds.push_back(static_cast<uint32_t>(std::atoi(item.c_str())));
}
}

Expand All @@ -1736,7 +1746,7 @@ static bool dimensionsToLabels(const std::string& labelStr, std::vector<uint64_t
if (item == DEFAULT)
def = true;
else
labels.push_back(std::atoi(item.c_str()));
labels.push_back(static_cast<uint64_t>(std::atoi(item.c_str())));
}

return def;
Expand Down Expand Up @@ -1831,7 +1841,7 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType(tinyxml2::XMLElement
uint32_t length = types::MAX_ELEMENTS_COUNT;
if (lengthStr != nullptr)
{
length = std::stoi(lengthStr);
length = static_cast<uint32_t>(std::stoi(lengthStr));
}

if (!isArray)
Expand Down Expand Up @@ -1907,7 +1917,7 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType(tinyxml2::XMLElement
uint32_t length = types::MAX_ELEMENTS_COUNT;
if (lengthStr != nullptr)
{
length = std::stoi(lengthStr);
length = static_cast<uint32_t>(std::stoi(lengthStr));
}

if (!isArray)
Expand Down Expand Up @@ -2125,7 +2135,7 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType(tinyxml2::XMLElement
const char* boundStr = p_root->Attribute(STR_MAXLENGTH);
if (boundStr != nullptr)
{
bound = std::atoi(boundStr);
bound = static_cast<uint32_t>(std::atoi(boundStr));
}
if (!isArray)
{
Expand All @@ -2146,7 +2156,7 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType(tinyxml2::XMLElement
const char* boundStr = p_root->Attribute(STR_MAXLENGTH);
if (boundStr != nullptr)
{
bound = std::atoi(boundStr);
bound = static_cast<uint32_t>(std::atoi(boundStr));
}
if (!isArray)
{
Expand Down Expand Up @@ -2572,7 +2582,7 @@ template <typename T>
void XMLParser::addAllAttributes(tinyxml2::XMLElement* p_profile, DataNode<T>& node)
{
const tinyxml2::XMLAttribute* attrib;
for (attrib = p_profile->FirstAttribute(); attrib != NULL; attrib = attrib->Next())
for (attrib = p_profile->FirstAttribute(); attrib != nullptr; attrib = attrib->Next())
{
node.addAttribute(attrib->Name(), attrib->Value());
}
Expand Down Expand Up @@ -2637,7 +2647,7 @@ XMLP_ret XMLParser::fillDataNode(tinyxml2::XMLElement* p_profile, DataNode<Parti
uint8_t ident = 1;
tinyxml2::XMLElement *p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_element->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
for (p_aux0 = p_element->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, DEF_UNI_LOC_LIST) == 0)
Expand Down Expand Up @@ -2763,7 +2773,7 @@ XMLP_ret XMLParser::fillDataNode(tinyxml2::XMLElement* p_profile, DataNode<Publi
uint8_t ident = 1;
tinyxml2::XMLElement *p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_profile->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
for (p_aux0 = p_profile->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, TOPIC) == 0)
Expand Down Expand Up @@ -2883,7 +2893,7 @@ XMLP_ret XMLParser::fillDataNode(tinyxml2::XMLElement* p_profile, DataNode<Subsc
uint8_t ident = 1;
tinyxml2::XMLElement *p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_profile->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
for (p_aux0 = p_profile->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, TOPIC) == 0)
Expand Down
6 changes: 6 additions & 0 deletions test/unittest/xmlparser/XMLProfileParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class XMLProfileParserTests: public ::testing::Test
{
delete log_mock;
}

protected:
void SetUp() override
{
xmlparser::XMLProfileManager::DeleteInstance();
}
};

TEST_F(XMLProfileParserTests, XMLoadProfiles)
Expand Down