diff options
author | Edwin Mons <edwin.mons@isode.com> | 2018-11-09 09:15:38 (GMT) |
---|---|---|
committer | Edwin Mons <edwin.mons@isode.com> | 2018-11-09 13:43:02 (GMT) |
commit | 56384396e5501ebcf7276caa2cb561023d3c3d12 (patch) | |
tree | a9365158591c420fe4fe16e661264b9d56f54bce /Swiften/Parser/ExpatParser.cpp | |
parent | a45eed2d826f60a20dfd1f4f06df37d1f83263f8 (diff) | |
download | swift-56384396e5501ebcf7276caa2cb561023d3c3d12.zip swift-56384396e5501ebcf7276caa2cb561023d3c3d12.tar.bz2 |
Remove numeric_casts from XML parsers
The code has been updated to use asserts where a sensible recovery path
was deemed impossible, and a conditional return for parse. In general,
our XML parsing will fail for any single parse of a document over
roughly 2 2GiB, which is probably not going to be a practical issue soon.
Test-Information:
Unit tests pass on macOS 10.13 using Expat and Debian 9 using LibXML
Change-Id: I3a8da802860028ea278b322af081c2b22b55a442
Diffstat (limited to 'Swiften/Parser/ExpatParser.cpp')
-rw-r--r-- | Swiften/Parser/ExpatParser.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index 77d959c..8415c42 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -7,13 +7,12 @@ #include <Swiften/Parser/ExpatParser.h> #include <cassert> +#include <limits> #include <memory> #include <string> #include <expat.h> -#include <boost/numeric/conversion/cast.hpp> - #include <Swiften/Base/String.h> #include <Swiften/Parser/XMLParserClient.h> @@ -84,7 +83,10 @@ ExpatParser::~ExpatParser() { } bool ExpatParser::parse(const std::string& data) { - bool success = XML_Parse(p->parser_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_STATUS_OK; + if (data.size() > std::numeric_limits<int>::max()) { + return false; + } + bool success = XML_Parse(p->parser_, data.c_str(), static_cast<int>(data.size()), false) == XML_STATUS_OK; /*if (!success) { std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl; }*/ |