From: Jérémie Galarneau Date: Fri, 15 Nov 2019 22:16:32 +0000 (-0500) Subject: Fix: relayd: check for a trace chunk before writing a packet X-Git-Tag: v2.12.0-rc1~240 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=1ad1103bedd3f87c3cbe151e1ef61fbaceaa0f4c Fix: relayd: check for a trace chunk before writing a packet Protocol errors can cause a packet to be written to a stream that doesn't have an active trace chunk. Validate this condition for the init and write packet operations on a stream. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/stream.c b/src/bin/lttng-relayd/stream.c index 9d753bd0a..35ed262d6 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.c @@ -955,6 +955,14 @@ int stream_init_packet(struct relay_stream *stream, size_t packet_size, int ret = 0; ASSERT_LOCKED(stream->lock); + + if (!stream->stream_fd || !stream->trace_chunk) { + ERR("Protocol error: received a packet for a stream that doesn't have a current trace chunk: stream_id = %" PRIu64 ", channel_name = %s", + stream->stream_handle, stream->channel_name); + ret = -1; + goto end; + } + if (caa_likely(stream->tracefile_size == 0)) { /* No size limit set; nothing to check. */ goto end; @@ -1020,6 +1028,12 @@ int stream_write(struct relay_stream *stream, memset(padding_buffer, 0, min(sizeof(padding_buffer), padding_to_write)); + if (!stream->stream_fd || !stream->trace_chunk) { + ERR("Protocol error: received a packet for a stream that doesn't have a current trace chunk: stream_id = %" PRIu64 ", channel_name = %s", + stream->stream_handle, stream->channel_name); + ret = -1; + goto end; + } if (packet) { write_ret = lttng_write(stream->stream_fd->fd, packet->data, packet->size);