diff options
-rw-r--r-- | Swiften/Parser/ExpatParser.cpp | 8 | ||||
-rw-r--r-- | Swiften/Parser/LibXMLParser.cpp | 16 |
2 files changed, 15 insertions, 9 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 @@ -9,2 +9,3 @@ #include <cassert> +#include <limits> #include <memory> @@ -14,4 +15,2 @@ -#include <boost/numeric/conversion/cast.hpp> - #include <Swiften/Base/String.h> @@ -86,3 +85,6 @@ 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) { diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index be0a92d..5bd3737 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -1,3 +1,3 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. @@ -10,2 +10,3 @@ #include <cstring> +#include <limits> #include <memory> @@ -13,4 +14,2 @@ -#include <boost/numeric/conversion/cast.hpp> - #include <libxml/parser.h> @@ -38,2 +37,3 @@ static void handleStartElement(void* parser, const xmlChar* name, const xmlChar* } + assert(attributes[i+4] >= attributes[i+3]); attributeValues.addAttribute( @@ -42,3 +42,3 @@ static void handleStartElement(void* parser, const xmlChar* name, const xmlChar* std::string(reinterpret_cast<const char*>(attributes[i+3]), - boost::numeric_cast<size_t>(attributes[i+4]-attributes[i+3]))); + static_cast<size_t>(attributes[i+4]-attributes[i+3]))); } @@ -52,3 +52,4 @@ static void handleEndElement(void *parser, const xmlChar* name, const xmlChar*, static void handleCharacterData(void* parser, const xmlChar* data, int len) { - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), boost::numeric_cast<size_t>(len))); + assert(len >= 0); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), static_cast<size_t>(len))); } @@ -96,3 +97,6 @@ LibXMLParser::~LibXMLParser() { bool LibXMLParser::parse(const std::string& data) { - if (xmlParseChunk(p->context_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_ERR_OK) { + if (data.size() > std::numeric_limits<int>::max()) { + return false; + } + if (xmlParseChunk(p->context_, data.c_str(), static_cast<int>(data.size()), false) == XML_ERR_OK) { return true; |