mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
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.
This commit is contained in:
@@ -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'.
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user