diff --git a/boost/network/uri/decode.hpp b/boost/network/uri/decode.hpp index e9e80e984..7503d5665 100644 --- a/boost/network/uri/decode.hpp +++ b/boost/network/uri/decode.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -58,9 +59,9 @@ OutputIterator decode(const InputIterator &in_begin, OutputIterator out = out_begin; while (it != in_end) { if (*it == '%') { - ++it; + if (++it == in_end) throw std::out_of_range("unexpected end of stream"); value_type v0 = detail::letter_to_hex(*it); - ++it; + if (++it == in_end) throw std::out_of_range("unexpected end of stream"); value_type v1 = detail::letter_to_hex(*it); ++it; *out++ = 0x10 * v0 + v1; diff --git a/libs/network/test/uri/uri_encoding_test.cpp b/libs/network/test/uri/uri_encoding_test.cpp index aaff45dbf..2c2ddaaf6 100644 --- a/libs/network/test/uri/uri_encoding_test.cpp +++ b/libs/network/test/uri/uri_encoding_test.cpp @@ -47,3 +47,10 @@ BOOST_AUTO_TEST_CASE(decoding_multibyte_test) { uri::decode(encoded, std::back_inserter(instance)); BOOST_CHECK_EQUAL(instance, unencoded); } + +BOOST_AUTO_TEST_CASE(decoding_throw_test) { + const std::string encoded("%"); + + std::string instance; + BOOST_CHECK_THROW(uri::decoded(encoded), std::out_of_range); +}