Skip to content

Commit 0dfa5fc

Browse files
authored
Add extra checks in CXMLImpl::ParseString to avoid crash when invalid XML data supplied (#2282)
* Add extra checks in CXMLImpl::ParseString * Change back to default encoding (left from testing)
1 parent 4b15cc3 commit 0dfa5fc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Shared/XML/CXMLImpl.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ std::unique_ptr<SXMLString> CXMLImpl::ParseString(const char* strXmlContent)
5050
if (!xmlDoc->Error())
5151
{
5252
TiXmlElement* xmlDocumentRoot = xmlDoc->RootElement();
53-
CXMLNodeImpl* xmlBaseNode = new CXMLNodeImpl(nullptr, nullptr, *xmlDocumentRoot);
54-
xmlBaseNode->BuildFromDocument();
55-
return std::unique_ptr<SXMLString>(new SXMLStringImpl(xmlDoc, xmlBaseNode));
53+
54+
if (xmlDocumentRoot)
55+
{
56+
CXMLNodeImpl* xmlBaseNode = new CXMLNodeImpl(nullptr, nullptr, *xmlDocumentRoot);
57+
58+
if (xmlBaseNode && xmlBaseNode->IsValid())
59+
{
60+
xmlBaseNode->BuildFromDocument();
61+
return std::unique_ptr<SXMLString>(new SXMLStringImpl(xmlDoc, xmlBaseNode));
62+
}
63+
}
5664
}
5765
}
5866
return nullptr;

0 commit comments

Comments
 (0)