From 8098cba4c2891007bb49cc1d8ba3924a8d00536e Mon Sep 17 00:00:00 2001 From: Mike Ellery Date: Wed, 20 Jun 2018 17:18:57 -0700 Subject: [PATCH] Trim space in Endpoint::from_string Fixes: RIPD-1643 --- src/ripple/beast/net/impl/IPEndpoint.cpp | 3 ++- src/test/beast/IPEndpoint_test.cpp | 5 +++++ src/test/core/Config_test.cpp | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ripple/beast/net/impl/IPEndpoint.cpp b/src/ripple/beast/net/impl/IPEndpoint.cpp index d757abac4..eb0e2dbd9 100644 --- a/src/ripple/beast/net/impl/IPEndpoint.cpp +++ b/src/ripple/beast/net/impl/IPEndpoint.cpp @@ -21,6 +21,7 @@ #endif #include +#include namespace beast { namespace IP { @@ -38,7 +39,7 @@ Endpoint::Endpoint (Address const& addr, Port port) std::pair Endpoint::from_string_checked (std::string const& s) { - std::stringstream is (s); + std::stringstream is (boost::trim_copy(s)); Endpoint endpoint; is >> endpoint; if (! is.fail() && is.rdbuf()->in_avail() == 0) diff --git a/src/test/beast/IPEndpoint_test.cpp b/src/test/beast/IPEndpoint_test.cpp index e671280dc..fe7dfa53d 100644 --- a/src/test/beast/IPEndpoint_test.cpp +++ b/src/test/beast/IPEndpoint_test.cpp @@ -219,6 +219,11 @@ public: shouldParseEPV4("1.2.3.4", {{1,2,3,4}}, 0); shouldParseEPV4("1.2.3.4:5", {{1,2,3,4}}, 5); shouldParseEPV4("1.2.3.4 5", {{1,2,3,4}}, 5, "1.2.3.4:5"); + // leading, trailing space + shouldParseEPV4(" 1.2.3.4:5", {{1,2,3,4}}, 5, "1.2.3.4:5"); + shouldParseEPV4("1.2.3.4:5 ", {{1,2,3,4}}, 5, "1.2.3.4:5"); + shouldParseEPV4("1.2.3.4 ", {{1,2,3,4}}, 0, "1.2.3.4"); + shouldParseEPV4(" 1.2.3.4", {{1,2,3,4}}, 0, "1.2.3.4"); shouldParseEPV6( "2001:db8:a0b:12f0::1", {{32, 01, 13, 184, 10, 11, 18, 240, 0, 0, 0, 0, 0, 0, 0, 1}}, diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index fd43906da..5d1a35f48 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,7 @@ port_wss_admin [port_rpc] port = 5005 ip = 127.0.0.1 -admin = 127.0.0.1 +admin = 127.0.0.1, ::1 protocol = https [port_peer] @@ -852,6 +853,24 @@ trustthesevalidators.gov } } + void testPort () + { + detail::RippledCfgGuard const cfg(*this, "testPort", "", ""); + auto const& conf = cfg.config(); + if (!BEAST_EXPECT(conf.exists("port_rpc"))) + return; + if (!BEAST_EXPECT(conf.exists("port_wss_admin"))) + return; + ParsedPort rpc; + if (!unexcept([&]() { parse_Port (rpc, conf["port_rpc"], log); })) + return; + BEAST_EXPECT(rpc.admin_ip && (rpc.admin_ip .get().size() == 2)); + ParsedPort wss; + if (!unexcept([&]() { parse_Port (wss, conf["port_wss_admin"], log); })) + return; + BEAST_EXPECT(wss.admin_ip && (wss.admin_ip .get().size() == 1)); + } + void run () override { testLegacy (); @@ -860,6 +879,7 @@ trustthesevalidators.gov testValidatorsFile (); testSetup (false); testSetup (true); + testPort (); } };