From 8d382dd4d4e95ea6ff88d6bd9f8a8fc85970ee3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 10 Sep 2019 19:30:33 -0400 Subject: [PATCH] Fix: session may be NULL in relay_create_session error path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A reply is sent in response to a session's creation even if it failed to be created. In those cases, session is null and its output_path should not be accessed. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 8e67f7664..2ffa75078 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1157,21 +1157,24 @@ send_reply: } } else { const uint32_t output_path_length = - strlen(session->output_path) + 1; + session ? strlen(session->output_path) + 1 : 0; reply.output_path_length = htobe32(output_path_length); - ret = lttng_dynamic_buffer_append(&reply_payload, &reply, - sizeof(reply)); + ret = lttng_dynamic_buffer_append( + &reply_payload, &reply, sizeof(reply)); if (ret) { ERR("Failed to append \"create session\" command reply header to payload buffer"); goto end; } - ret = lttng_dynamic_buffer_append(&reply_payload, - session->output_path, output_path_length); - if (ret) { - ERR("Failed to append \"create session\" command reply path to payload buffer"); - goto end; + if (output_path_length) { + ret = lttng_dynamic_buffer_append(&reply_payload, + session->output_path, + output_path_length); + if (ret) { + ERR("Failed to append \"create session\" command reply path to payload buffer"); + goto end; + } } } -- 2.34.1