summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-12-10 14:18:41 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-12-10 14:18:41 +0200
commita4e6b32ed9b5b43f9a0e9ae78676c7f32866e4fc (patch)
tree267b68371840c47e4c98bdb11820c3728b485b59 /src
parent85a7f31e2122b52a913a36a8af66f393e99e9bf0 (diff)
Limit ZMQ RPC requests to 999999 bytes at CPP side. (check also unzipped size)
Change-Id: Ic592d40678e9918f7d06b9ce4269a330c4455b3c Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp9
-rw-r--r--src/rpc-server/trex_rpc_jsonrpc_v2_parser.h9
-rw-r--r--src/rpc-server/trex_rpc_req_resp_server.cpp26
3 files changed, 31 insertions, 13 deletions
diff --git a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp
index 4fa2447d..d08de4e1 100644
--- a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp
+++ b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp
@@ -235,3 +235,12 @@ TrexJsonRpcV2Parser::generate_common_error(Json::Value &json, const std::string
}
+void
+TrexJsonRpcV2Parser::generate_common_error(std::string &response, const std::string &specific_err) {
+ Json::Value resp_json;
+ Json::FastWriter writer;
+
+ generate_common_error(resp_json, specific_err);
+ response = writer.write(resp_json);
+}
+
diff --git a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.h b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.h
index 0563f21d..d91cbe2d 100644
--- a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.h
+++ b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.h
@@ -89,6 +89,15 @@ public:
static void generate_common_error(Json::Value &json, const std::string &specific_err);
/**
+ * will generate a valid JSON RPC v2 error message with
+ * generic error code and message
+ *
+ * @author imarom (16-Sep-15)
+ *
+ */
+ static void generate_common_error(std::string &response, const std::string &specific_err);
+
+ /**
* *tries* to generate a pretty string from JSON
* if json_str is not a valid JSON string
* it will duplicate the source
diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp
index 729917c0..e762b8c1 100644
--- a/src/rpc-server/trex_rpc_req_resp_server.cpp
+++ b/src/rpc-server/trex_rpc_req_resp_server.cpp
@@ -172,13 +172,12 @@ void TrexRpcServerReqRes::handle_request(const std::string &request) {
std::string response;
if ( request.size() > MAX_RPC_MSG_LEN ) {
- response = "Request is too large (" + std::to_string(request.size()) + " bytes). Consider splitting to smaller chunks.";
- handle_server_error(response);
- return;
+ std::string err_msg = "Request is too large (" + std::to_string(request.size()) + " bytes). Consider splitting to smaller chunks.";
+ TrexJsonRpcV2Parser::generate_common_error(response, err_msg);
+ } else {
+ process_request(request, response);
}
- process_request(request, response);
-
zmq_send(m_socket, response.c_str(), response.size(), 0);
}
@@ -250,7 +249,12 @@ void TrexRpcServerReqRes::process_zipped_request(const std::string &request, std
/* process the request */
std::string raw_response;
- process_request_raw(unzipped, raw_response);
+ if ( unzipped.size() > MAX_RPC_MSG_LEN ) {
+ std::string err_msg = "Request is too large (" + std::to_string(unzipped.size()) + " bytes). Consider splitting to smaller chunks.";
+ TrexJsonRpcV2Parser::generate_common_error(raw_response, err_msg);
+ } else {
+ process_request_raw(unzipped, raw_response);
+ }
TrexRpcZip::compress(raw_response, response);
@@ -262,18 +266,14 @@ void TrexRpcServerReqRes::process_zipped_request(const std::string &request, std
*/
void
TrexRpcServerReqRes::handle_server_error(const std::string &specific_err) {
- Json::FastWriter writer;
- Json::Value response;
+ std::string response;
/* generate error */
TrexJsonRpcV2Parser::generate_common_error(response, specific_err);
- /* write the JSON to string and sever on ZMQ */
- std::string response_str = writer.write(response);
-
- verbose_json("Server Replied: ", response_str);
+ verbose_json("Server Replied: ", response);
- zmq_send(m_socket, response_str.c_str(), response_str.size(), 0);
+ zmq_send(m_socket, response.c_str(), response.size(), 0);
}