From bacc41cc41d9702241e7a52617fed046ed5f5506 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 16 Nov 2020 16:50:41 -0500 Subject: [PATCH] Fix: lttng-ctl: deserialize on orderly shutdown of sessiond MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue ===== The `recv_data_sessiond()` function may return zero if the socket peer has shutdown orderly. This happens if the session daemon is killed while the client is blocked on the `recv_data_sessiond()` call. Currently, when this happens, the client simply goes on to decode the uninitialized reply buffer. This bug was witnessed while developing the upcoming event-notifier feature where complex objects are received from sessiond and attempts to deserialize these objects resulted in segmentation faults. Solution ======== Return -LTTNG_ERR_NO_SESSIOND when `recvmsg()` returns zero. This way, the client can simply tell the user that the session daemon is no longer available. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Ib2387526c4101e3bae706e38181bfeb25da26fa3 --- src/lib/lttng-ctl/lttng-ctl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 001abffcd..1c51eedc7 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -211,6 +211,8 @@ static int recv_data_sessiond(void *buf, size_t len) { int ret; + assert(len > 0); + if (!connected) { ret = -LTTNG_ERR_NO_SESSIOND; goto end; @@ -219,6 +221,8 @@ static int recv_data_sessiond(void *buf, size_t len) ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len); if (ret < 0) { ret = -LTTNG_ERR_FATAL; + } else if (ret == 0) { + ret = -LTTNG_ERR_NO_SESSIOND; } end: -- 2.34.1