From b305e682ed0d0a74e2ed24fdb0cd427ccc6347a8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 7 Jun 2013 05:11:20 -0700 Subject: [PATCH] Only touch remote_endpoint under a try/catch block. --- src/cpp/ripple/RPCDoor.cpp | 10 +++++++++- src/cpp/ripple/WSHandler.h | 8 +++++++- src/cpp/ripple/ripple_Peer.cpp | 18 +++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/cpp/ripple/RPCDoor.cpp b/src/cpp/ripple/RPCDoor.cpp index a093751d1..b2df802f6 100644 --- a/src/cpp/ripple/RPCDoor.cpp +++ b/src/cpp/ripple/RPCDoor.cpp @@ -49,8 +49,16 @@ void RPCDoor::handleConnect(RPCServer::pointer new_connection, if (!error) { // Restrict callers by IP - if (!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string())) + try { + if (!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string())) + { + startListening(); + return; + } + } + catch (...) + { // client may have disconnected startListening(); return; } diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index 6a0a9e067..4e0de4cfb 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -141,7 +141,13 @@ public: { boost::mutex::scoped_lock sl(mMapLock); - mMap[cpClient] = boost::make_shared< WSConnection >(this, cpClient); + try + { + mMap[cpClient] = boost::make_shared< WSConnection >(this, cpClient); + } + catch (...) + { + } } void on_pong(connection_ptr cpClient, std::string data) diff --git a/src/cpp/ripple/ripple_Peer.cpp b/src/cpp/ripple/ripple_Peer.cpp index 3cf80d8ed..b48c1bfee 100644 --- a/src/cpp/ripple/ripple_Peer.cpp +++ b/src/cpp/ripple/ripple_Peer.cpp @@ -412,9 +412,21 @@ void PeerImp::handleConnect(const boost::system::error_code& error, boost::asio: // - We don't bother remembering the inbound IP or port. Only useful for debugging. void PeerImp::connected(const boost::system::error_code& error) { - boost::asio::ip::tcp::endpoint ep = getSocket().remote_endpoint(); - int iPort = ep.port(); - std::string strIp = ep.address().to_string(); + boost::asio::ip::tcp::endpoint ep; + int iPort; + std::string strIp; + + try + { + ep = getSocket().remote_endpoint(); + iPort = ep.port(); + strIp = ep.address().to_string(); + } + catch (...) + { + detach("edc", false); + return; + } mClientConnect = false; mIpPortConnect = make_pair(strIp, iPort);