goto end;
}
- data_size = be64toh(recv_hdr->data_size);
- payload_size = data_size;
- /*
- * Add 8 bytes (uint64_t) to the data size which is the value of the
- * stream_id and the payload size.
- */
- data_size += sizeof(uint64_t);
+ data_size = payload_size = be64toh(recv_hdr->data_size);
+ if (data_size < sizeof(struct lttcomm_relayd_metadata_payload)) {
+ ERR("Incorrect data size");
+ ret = -1;
+ goto end;
+ }
+ payload_size -= sizeof(struct lttcomm_relayd_metadata_payload);
+
if (data_buffer_size < data_size) {
data_buffer = realloc(data_buffer, data_size);
if (!data_buffer) {
/* Handle stream on the relayd if the output is on the network */
if (relayd) {
+ unsigned long netlen = len;
+
/*
* Lock the control socket for the complete duration of the function
* since from this point on we will use the socket.
if (stream->metadata_flag) {
/* Metadata requires the control socket. */
pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+ netlen += sizeof(stream->relayd_stream_id);
}
- ret = consumer_handle_stream_before_relayd(stream, len);
+ ret = consumer_handle_stream_before_relayd(stream, netlen);
if (ret >= 0) {
/* Use the returned socket. */
outfd = ret;
/* Handle stream on the relayd if the output is on the network */
if (relayd) {
+ unsigned long netlen = len;
+
if (stream->metadata_flag) {
/* Only lock if metadata since we use the control socket. */
pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+ netlen += sizeof(stream->relayd_stream_id);
}
- ret = consumer_handle_stream_before_relayd(stream, len);
+ ret = consumer_handle_stream_before_relayd(stream, netlen);
if (ret >= 0) {
outfd = ret;