Skip to content

Commit 69b4789

Browse files
nbougalisvinniefalco
authored andcommitted
Correctly parse multi-buffer JSON messages (RIPD-1306):
When attempting to parse a BufferSequence as a JSON object, if the sequence contained more than buffer, the JSON parser would incorrectly attempt to decode each buffer as a separate JSON object, instead of one complete object.
1 parent 4185102 commit 69b4789

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/ripple/json/json_reader.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,11 @@ bool
176176
Reader::parse(Value& root, BufferSequence const& bs)
177177
{
178178
using namespace boost::asio;
179+
std::string s;
180+
s.reserve (buffer_size(bs));
179181
for (auto const& b : bs)
180-
{
181-
auto begin = buffer_cast<const char*>(b);
182-
if(! parse(begin, begin + buffer_size(b), root))
183-
return false;
184-
}
185-
return true;
182+
s.append(buffer_cast<char const*>(b), buffer_size(b));
183+
return parse(s, root);
186184
}
187185

188186
/** \brief Read from 'sin' into 'root'.

src/test/app/Regression_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,9 @@ struct Regression_test : public beast::unit_test::suite
208208

209209
std::string const request = R"json({"command":"path_find","id":19,"subcommand":"create","source_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_amount":"1000000","source_currencies":[{"currency":"0000000000000000000000000000000000000000"},{"currency":"0000000000000000000000005553440000000000"},{"currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004555520000000000"},{"currency":"0000000000000000000000004554480000000000"},{"currency":"0000000000000000000000004A50590000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"000000000000000000000000434E590000000000"},{"currency":"0000000000000000000000004742490000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004341440000000000"}]})json";
210210

211-
212211
Json::Value jvRequest;
213212
Json::Reader jrReader;
214213

215-
216214
std::vector<boost::asio::const_buffer> buffers;
217215
buffers.emplace_back(buffer(request, 1024));
218216
buffers.emplace_back(buffer(request.data() + 1024, request.length() - 1024));

0 commit comments

Comments
 (0)