[lttng-dev] [PATCH lttng-tools 1/2] Fix: fail on relayd lookup when finding a relayd is expected

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Mon May 8 15:22:53 UTC 2017


An actual relayd lookup error leads to using the code path of a local
handling. Since stream->index_file is null when expecting a relayd, using
the code path for local handling result in an null access.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 src/common/consumer/consumer-stream.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/common/consumer/consumer-stream.c b/src/common/consumer/consumer-stream.c
index 522b3cd5..23654d38 100644
--- a/src/common/consumer/consumer-stream.c
+++ b/src/common/consumer/consumer-stream.c
@@ -359,18 +359,24 @@ int consumer_stream_write_index(struct lttng_consumer_stream *stream,
 		struct ctf_packet_index *element)
 {
 	int ret;
-	struct consumer_relayd_sock_pair *relayd;
 
 	assert(stream);
 	assert(element);
 
 	rcu_read_lock();
-	relayd = consumer_find_relayd(stream->net_seq_idx);
-	if (relayd) {
-		pthread_mutex_lock(&relayd->ctrl_sock_mutex);
-		ret = relayd_send_index(&relayd->control_sock, element,
+	if (stream->net_seq_idx != (uint64_t) -1ULL) {
+		struct consumer_relayd_sock_pair *relayd;
+		relayd = consumer_find_relayd(stream->net_seq_idx);
+		if (relayd) {
+			pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+			ret = relayd_send_index(&relayd->control_sock, element,
 				stream->relayd_stream_id, stream->next_net_seq_num - 1);
-		pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
+			pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
+		} else {
+			ERR("Stream %" PRIu64 " relayd ID %" PRIu64 " unknown. Can't write index.",
+					stream->key, stream->net_seq_idx);
+			ret = -1;
+		}
 	} else {
 		if (lttng_index_file_write(stream->index_file, element)) {
 			ret = -1;
@@ -378,6 +384,7 @@ int consumer_stream_write_index(struct lttng_consumer_stream *stream,
 			ret = 0;
 		}
 	}
+
 	if (ret < 0) {
 		goto error;
 	}
-- 
2.11.0



More information about the lttng-dev mailing list