diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9c5487..de00b40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 181: + +* Fix parse_dec algorithm + +-------------------------------------------------------------------------------- + Version 180: * Fix http_server_stackless_ssl.cpp example diff --git a/doc/qbk/09_releases.qbk b/doc/qbk/09_releases.qbk index 8350fc18..53b7fe22 100644 --- a/doc/qbk/09_releases.qbk +++ b/doc/qbk/09_releases.qbk @@ -74,6 +74,8 @@ in future versions. * ([issue 1210]) Fix http_server_stackless_ssl.cpp example +* ([issue 1211]) Fix parse_dec algorithm + * Tidy up websocket stream javadocs * Fix move-only arguments in [link beast.ref.boost__beast__bind_handler `bind_handler`] diff --git a/include/boost/beast/http/detail/basic_parser.hpp b/include/boost/beast/http/detail/basic_parser.hpp index 0936862a..818277be 100644 --- a/include/boost/beast/http/detail/basic_parser.hpp +++ b/include/boost/beast/http/detail/basic_parser.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace boost { @@ -26,9 +27,8 @@ namespace beast { namespace http { namespace detail { -class basic_parser_base +struct basic_parser_base { -protected: // limit on the size of the obs-fold buffer // // https://stackoverflow.com/questions/686217/maximum-on-http-header-values @@ -299,25 +299,30 @@ protected: return p; } - template + template static - bool - parse_dec(Iter it, Iter last, Unsigned& v) + typename std::enable_if< + std::numeric_limits::is_integer && + ! std::numeric_limits::is_signed, bool>::type + parse_dec(Iter it, Iter last, T& v) { - if(! is_digit(*it)) + if(it == last) return false; - v = *it - '0'; - for(;;) + T tmp = 0; + do { - if(! is_digit(*++it)) - break; - auto const d = *it - '0'; - if(v > ((std::numeric_limits< - Unsigned>::max)() - 10) / 10) + if((! is_digit(*it)) || + tmp > (std::numeric_limits::max)() / 10) return false; - v = 10 * v + d; + tmp *= 10; + T const d = *it - '0'; + if((std::numeric_limits::max)() - tmp < d) + return false; + tmp += d; } - return it == last; + while(++it != last); + v = tmp; + return true; } template