From 69b47890e69cea46c403e6354742c3653f125c6f Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Fri, 30 Sep 2016 18:41:36 -0700 Subject: [PATCH] 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. --- src/ripple/json/json_reader.h | 10 ++++------ src/test/app/Regression_test.cpp | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ripple/json/json_reader.h b/src/ripple/json/json_reader.h index c60e4822886..3367dc6c1a5 100644 --- a/src/ripple/json/json_reader.h +++ b/src/ripple/json/json_reader.h @@ -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(b); - if(! parse(begin, begin + buffer_size(b), root)) - return false; - } - return true; + s.append(buffer_cast(b), buffer_size(b)); + return parse(s, root); } /** \brief Read from 'sin' into 'root'. diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 1df46477bcf..c167af17707 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -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 buffers; buffers.emplace_back(buffer(request, 1024)); buffers.emplace_back(buffer(request.data() + 1024, request.length() - 1024));