From: Jérémie Galarneau Date: Wed, 11 Sep 2019 16:03:38 +0000 (-0400) Subject: relayd: fix: rotate_truncate_stream() assumes non-null next chunk X-Git-Tag: v2.11.0-rc4~55 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=94a74983e5e660eef7678f5a18d3181d0e511a75;p=lttng-tools.git relayd: fix: rotate_truncate_stream() assumes non-null next chunk While the protocol doesn't allow a stream rotation position in the past when rotating to a "NULL" trace chunk, a misbehaving peer could express this. Report the protocol error and abort the truncation operation in this case. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/stream.c b/src/bin/lttng-relayd/stream.c index f98b46557..06e82b291 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.c @@ -210,6 +210,16 @@ static int rotate_truncate_stream(struct relay_stream *stream) struct stream_fd *previous_stream_fd = NULL; struct lttng_trace_chunk *previous_chunk = NULL; + if (!LTTNG_OPTIONAL_GET(&stream->ongoing_rotation)->next_trace_chunk) { + ERR("Protocol error encoutered in %s(): stream rotation " + "sequence number is before the current sequence number " + "and the next trace chunk is unset. Honoring this " + "rotation command would result in data loss", + __FUNCTION__); + ret = -1; + goto end; + } + ASSERT_LOCKED(stream->lock); /* * Acquire a reference to the current trace chunk to ensure @@ -245,6 +255,7 @@ static int rotate_truncate_stream(struct relay_stream *stream) goto end; } + assert(stream->stream_fd); /* * Seek the current tracefile to the position at which the rotation * should have occurred.