summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp24
-rw-r--r--src/stateless/cp/trex_stream.h2
2 files changed, 14 insertions, 12 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index dc8a9ccd..69e5dd18 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -65,17 +65,27 @@ TrexRpcCmdAddStream::_run(const Json::Value &params, Json::Value &result) {
const Json::Value &pkt = parse_object(section, "packet", result);
std::string pkt_binary = base64_decode(parse_string(pkt, "binary", result));
+ /* check packet size */
+ if ( (pkt_binary.size() < TrexStream::MIN_PKT_SIZE_BYTES) || (pkt_binary.size() > TrexStream::MAX_PKT_SIZE_BYTES) ) {
+ std::stringstream ss;
+ ss << "bad packet size provided: should be between " << TrexStream::MIN_PKT_SIZE_BYTES << " and " << TrexStream::MAX_PKT_SIZE_BYTES;
+ delete stream;
+ generate_execute_err(result, ss.str());
+ }
+
/* fetch the packet from the message */
- stream->m_pkt.len = pkt_binary.size();
- stream->m_pkt.binary = new uint8_t[pkt_binary.size()];
+ stream->m_pkt.len = std::max(pkt_binary.size(), 60UL);
+
+ /* allocate and init to zero ( with () ) */
+ stream->m_pkt.binary = new uint8_t[pkt_binary.size()]();
if (!stream->m_pkt.binary) {
generate_internal_err(result, "unable to allocate memory");
}
- /* copy the packet */
const char *pkt_buffer = pkt_binary.c_str();
+ /* copy the packet - if less than 60 it will remain zeroes */
for (int i = 0; i < pkt_binary.size(); i++) {
stream->m_pkt.binary[i] = pkt_buffer[i];
}
@@ -306,14 +316,6 @@ TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, TrexStream *stream, Json::V
void
TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &result) {
- /* check packet size */
- if ( (stream->m_pkt.len < TrexStream::MIN_PKT_SIZE_BYTES) || (stream->m_pkt.len > TrexStream::MAX_PKT_SIZE_BYTES) ) {
- std::stringstream ss;
- ss << "bad packet size provided: should be between " << TrexStream::MIN_PKT_SIZE_BYTES << " and " << TrexStream::MAX_PKT_SIZE_BYTES;
- delete stream;
- generate_execute_err(result, ss.str());
- }
-
/* add the stream to the port's stream table */
TrexStatelessPort * port = get_stateless_obj()->get_port_by_id(stream->m_port_id);
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index 6bb30cf9..80d64ec5 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -125,7 +125,7 @@ public:
virtual ~TrexStream();
/* defines the min max per packet supported */
- static const uint32_t MIN_PKT_SIZE_BYTES = 60;
+ static const uint32_t MIN_PKT_SIZE_BYTES = 14;
static const uint32_t MAX_PKT_SIZE_BYTES = MAX_PKT_SIZE;
/* provides storage for the stream json*/