From 41851022d365a8ed3f36b71c62f73da28b8f788b Mon Sep 17 00:00:00 2001 From: Edward Hennis Date: Fri, 30 Sep 2016 20:37:22 -0400 Subject: [PATCH 1/3] Add regression test for multi-buffer JSON message parsing (RIPD-1306) --- src/test/app/Regression_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 89d4dbba8..1df46477b 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -199,12 +200,33 @@ struct Regression_test : public beast::unit_test::suite } } + void testJsonInvalid() + { + using namespace jtx; + using boost::asio::buffer; + testcase("jsonInvalid"); + + 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)); + BEAST_EXPECT(jrReader.parse(jvRequest, buffers) && + jvRequest && jvRequest.isObject()); + } + void run() override { testOffer1(); testLowBalanceDestroy(); testSecp256r1key(); testFeeEscalationAutofill(); + testJsonInvalid(); } }; From 69b47890e69cea46c403e6354742c3653f125c6f Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Fri, 30 Sep 2016 18:41:36 -0700 Subject: [PATCH 2/3] 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 c60e48228..3367dc6c1 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 1df46477b..c167af177 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)); From 98f878cf10a32e26021b6a6ed44990bccbbc92c2 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 1 Oct 2016 12:12:34 -0400 Subject: [PATCH 3/3] Set version to 0.33.0-hf1 --- src/ripple/protocol/impl/BuildInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ripple/protocol/impl/BuildInfo.cpp b/src/ripple/protocol/impl/BuildInfo.cpp index deef073ec..95308bf76 100644 --- a/src/ripple/protocol/impl/BuildInfo.cpp +++ b/src/ripple/protocol/impl/BuildInfo.cpp @@ -34,7 +34,7 @@ char const* const versionString = // The build version number. You must edit this for each release // and follow the format described at http://semver.org/ // - "0.33.0" + "0.33.0-hf1" #if defined(DEBUG) || defined(SANITIZER) "+"