Skip to content

Commit 947cc7e

Browse files
committed
Merge pull request cpp-netlib#553 from cnagune/0.11-devel-fix-decode-percent
fix boost::network::uri::decode error - out of range because of '%'
2 parents b540ff3 + 8f5831f commit 947cc7e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

boost/network/uri/decode.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/range/begin.hpp>
1111
#include <boost/range/end.hpp>
1212
#include <cassert>
13+
#include <stdexcept>
1314

1415
namespace boost {
1516
namespace network {
@@ -58,9 +59,9 @@ OutputIterator decode(const InputIterator &in_begin,
5859
OutputIterator out = out_begin;
5960
while (it != in_end) {
6061
if (*it == '%') {
61-
++it;
62+
if (++it == in_end) throw std::out_of_range("unexpected end of stream");
6263
value_type v0 = detail::letter_to_hex(*it);
63-
++it;
64+
if (++it == in_end) throw std::out_of_range("unexpected end of stream");
6465
value_type v1 = detail::letter_to_hex(*it);
6566
++it;
6667
*out++ = 0x10 * v0 + v1;

libs/network/test/uri/uri_encoding_test.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ BOOST_AUTO_TEST_CASE(decoding_multibyte_test) {
4747
uri::decode(encoded, std::back_inserter(instance));
4848
BOOST_CHECK_EQUAL(instance, unencoded);
4949
}
50+
51+
BOOST_AUTO_TEST_CASE(decoding_throw_test) {
52+
const std::string encoded("%");
53+
54+
std::string instance;
55+
BOOST_CHECK_THROW(uri::decoded(encoded), std::out_of_range);
56+
}

0 commit comments

Comments
 (0)