Fix: session may be NULL in relay_create_session error path
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 10 Sep 2019 23:30:33 +0000 (19:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 10 Sep 2019 23:30:33 +0000 (19:30 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/main.c

index 8e67f7664f6a44828cae6c2dd078b4c5d06b3ad9..2ffa75078779b7d0b9986696f5643267ca5ea7aa 100644 (file)
@@ -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;
+                       }
                }
        }
 
This page took 0.03583 seconds and 4 git commands to generate.