From 79a4298098da8ec2d118e00ca2a08e7b542e7287 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 28 Oct 2019 23:32:36 -0400 Subject: [PATCH] Fix: relayd: live: crash on attach to a session without trace chunk MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Attaching to a session that doesn't have a current trace chunk results in a crash when the viewer streams are created from a NULL viewer trace chunk. Live clients are prevented from attaching to sessions without a current trace chunk as those sessions are either being destroyed or too young to have a trace chunk, meaning that they don't have streams yet. Live clients will receive the "unknown" status code that they already receive when asking an unknown session. Since such sessions are not listed, this shouldn't change any exposed behaviour. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/live.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 8c4f501aa..e480f86e4 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -1080,6 +1080,15 @@ int viewer_attach_session(struct relay_connection *conn) DBG("Attach session ID %" PRIu64 " received", session_id); pthread_mutex_lock(&session->lock); + if (!session->current_trace_chunk) { + /* + * Session is either being destroyed or it never had a trace + * chunk created against it. + */ + DBG("Session requested by live client has no current trace chunk, returning unknown session"); + response.status = htobe32(LTTNG_VIEWER_ATTACH_UNK); + goto send_reply; + } if (session->live_timer == 0) { DBG("Not live session"); response.status = htobe32(LTTNG_VIEWER_ATTACH_NOT_LIVE); -- 2.34.1