From 3380253bf913a26df2ef03c0361d6376fab70da9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 18 Oct 2012 14:27:54 -0700 Subject: [PATCH] Some cleanups. --- src/HTTPRequest.cpp | 4 +--- src/HTTPRequest.h | 3 +-- src/RPCServer.cpp | 12 +++++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/HTTPRequest.cpp b/src/HTTPRequest.cpp index a289ded0b..c3f365e0e 100644 --- a/src/HTTPRequest.cpp +++ b/src/HTTPRequest.cpp @@ -50,7 +50,6 @@ HTTPRequestAction HTTPRequest::consume(boost::asio::streambuf& buf) bShouldClose = sRequest.find("HTTP/1.1") == std::string::npos; eState = await_header; -// cLog(lsTRACE) << "Got first line. Going to header state"; return haREAD_LINE; } @@ -60,11 +59,10 @@ HTTPRequestAction HTTPRequest::consume(boost::asio::streambuf& buf) { if (iDataSize == 0) { // no body - eState = bShouldClose ? await_close : await_reset; + eState = do_request; return haDO_REQUEST; } eState = getting_body; -// cLog(lsTRACE) << "Got header, need body: " << iDataSize; return haREAD_RAW; } vHeaders.push_back(line); diff --git a/src/HTTPRequest.h b/src/HTTPRequest.h index 0d36c8d4f..9ecea2443 100644 --- a/src/HTTPRequest.h +++ b/src/HTTPRequest.h @@ -24,8 +24,7 @@ protected: await_request, // We are waiting for the request line await_header, // We are waiting for request headers getting_body, // We are waiting for the body - await_close, // We are waiting for the request to complete so we can close the connection - await_reset // We are waiting for the request to complete so we can reset the connection + do_request, // We are waiting for the request to complete }; state eState; diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 8fed71d8a..046a8946d 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -29,6 +29,10 @@ SETUP_LOG(); +#ifndef RPC_MAXIMUM_QUERY +#define RPC_MAXIMUM_QUERY (1024*1024) +#endif + RPCServer::RPCServer(boost::asio::io_service& io_service , NetworkOPs* nopNetwork) : mNetOps(nopNetwork), mSocket(io_service) { @@ -152,7 +156,13 @@ void RPCServer::handle_read_line(const boost::system::error_code& e) else if (action == haREAD_RAW) { int rLen = mHTTPRequest.getDataSize(); - assert(rLen > 0); + if ((rLen < 0) || (rLen > RPC_MAXIMUM_QUERY)) + { + cLog(lsWARNING) << "Illegal RPC request length " << rLen; + boost::system::error_code ignore_ec; + mSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_ec); + return; + } int alreadyHave = mLineBuffer.size();