Skip to content

Commit

Permalink
Correctly parse multi-buffer JSON messages (RIPD-1306):
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nbougalis authored and vinniefalco committed Oct 1, 2016
1 parent 4185102 commit 69b4789
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/ripple/json/json_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ bool
Reader::parse(Value& root, BufferSequence const& bs)
{
using namespace boost::asio;
std::string s;
s.reserve (buffer_size(bs));
for (auto const& b : bs)
{
auto begin = buffer_cast<const char*>(b);
if(! parse(begin, begin + buffer_size(b), root))
return false;
}
return true;
s.append(buffer_cast<char const*>(b), buffer_size(b));
return parse(s, root);
}

/** \brief Read from 'sin' into 'root'.
Expand Down
2 changes: 0 additions & 2 deletions src/test/app/Regression_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ struct Regression_test : public beast::unit_test::suite

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";


Json::Value jvRequest;
Json::Reader jrReader;


std::vector<boost::asio::const_buffer> buffers;
buffers.emplace_back(buffer(request, 1024));
buffers.emplace_back(buffer(request.data() + 1024, request.length() - 1024));
Expand Down

0 comments on commit 69b4789

Please sign in to comment.