Fix: consumerd: type confusion in lttng_consumer_send_error
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 7 Mar 2023 19:38:32 +0000 (14:38 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 5 Apr 2024 16:12:29 +0000 (12:12 -0400)
lttng_consumer_send_error sends an lttcomm_return_code to the session
daemon. However, the size of lttcomm_sessiond_command was used.

This was probably missed since the function accepts an integer instead
of a proper enum type.

The size accepted by the function is changed to use lttcomm_return_code
and the size of a fixed-size type is used to send the error code to the
session daemon.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I318e6a8d145373779d11557a70e43abca9783e5c

src/bin/lttng-sessiond/manage-consumer.cpp
src/common/consumer/consumer.cpp
src/common/consumer/consumer.hpp

index b7eb10800fcaf2e21dd42e7de661a7568dc5597e..27a368e7f19d80d7dbaed75ee6c64f3eb61b28ca 100644 (file)
@@ -164,8 +164,13 @@ static void *thread_consumer_management(void *data)
 
        DBG2("Receiving code from consumer err_sock");
 
-       /* Getting status code from kconsumerd */
-       ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code));
+       /* Getting status code from consumerd */
+       {
+               std::int32_t comm_code = 0;
+
+               ret = lttcomm_recv_unix_sock(sock, &comm_code, sizeof(comm_code));
+               code = static_cast<decltype(code)>(comm_code);
+       }
        if (ret <= 0) {
                mark_thread_intialization_as_failed(notifiers);
                goto error;
@@ -304,9 +309,14 @@ static void *thread_consumer_management(void *data)
                                        goto error;
                                }
                                health_code_update();
-                               /* Wait for any kconsumerd error */
-                               ret = lttcomm_recv_unix_sock(
-                                       sock, &code, sizeof(enum lttcomm_return_code));
+                               /* Wait for any consumerd error */
+                               {
+                                       std::int32_t comm_code = 0;
+
+                                       ret = lttcomm_recv_unix_sock(
+                                               sock, &comm_code, sizeof(comm_code));
+                                       code = static_cast<decltype(code)>(comm_code);
+                               }
                                if (ret <= 0) {
                                        ERR("consumer closed the command socket");
                                        goto error;
index 7e7e7d384cd20565e48bf3bad2793a41f31d1ca6..ed844f8dfd8a4d27826ea6b8644d04fc244b0014 100644 (file)
@@ -45,6 +45,7 @@
 #include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <type_traits>
 #include <unistd.h>
 
 lttng_consumer_global_data the_consumer_data;
@@ -1255,11 +1256,17 @@ void lttng_consumer_set_command_sock_path(struct lttng_consumer_local_data *ctx,
  * Send return code to the session daemon.
  * If the socket is not defined, we return 0, it is not a fatal error
  */
-int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, int cmd)
+int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx,
+                             enum lttcomm_return_code error_code)
 {
        if (ctx->consumer_error_socket > 0) {
+               const std::int32_t comm_code = std::int32_t(error_code);
+
+               static_assert(
+                       sizeof(comm_code) >= sizeof(std::underlying_type<lttcomm_return_code>),
+                       "Fixed-size communication type too small to accomodate lttcomm_return_code");
                return lttcomm_send_unix_sock(
-                       ctx->consumer_error_socket, &cmd, sizeof(enum lttcomm_sessiond_command));
+                       ctx->consumer_error_socket, &comm_code, sizeof(comm_code));
        }
 
        return 0;
index c62e014530bfabdc39a28fb333f2d586056af384..310969172d73f656a258d038cfdb1c0c55c9441f 100644 (file)
@@ -921,7 +921,8 @@ void lttng_consumer_set_command_sock_path(struct lttng_consumer_local_data *ctx,
  * Returns the return code of sendmsg : the number of bytes transmitted or -1
  * on error.
  */
-int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx, int cmd);
+int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx,
+               enum lttcomm_return_code error_code);
 
 /*
  * Called from signal handler to ensure a clean exit.
This page took 0.029385 seconds and 4 git commands to generate.