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 18:58:56 +0000 (14:58 -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: Ib6a04969dd82857e3b8ac2ca2545cfb098b2d04f

src/bin/lttng-sessiond/manage-consumer.c
src/common/consumer/consumer.c
src/common/consumer/consumer.h

index 72e9a8600e93e01f1eab74942d14bd3ddf12f0b3..6980dfa33f5931af96b1e145e3e11613a4d3f9a8 100644 (file)
@@ -161,9 +161,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 */
+       {
+               int32_t comm_code = 0;
+
+               ret = lttcomm_recv_unix_sock(sock, &comm_code, sizeof(comm_code));
+               code = (typeof(code)) comm_code;
+       }
        if (ret <= 0) {
                mark_thread_intialization_as_failed(notifiers);
                goto error;
@@ -308,9 +312,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 */
+                               {
+                                       int32_t comm_code = 0;
+
+                                       ret = lttcomm_recv_unix_sock(
+                                               sock, &comm_code, sizeof(comm_code));
+                                       code = (typeof(code)) comm_code;
+                               }
                                if (ret <= 0) {
                                        ERR("consumer closed the command socket");
                                        goto error;
index fcb100e1a64ade8cf1c50b7c9f07bc55f931e39d..c457f754d230598ab52b7cd871c013449803e33a 100644 (file)
@@ -1272,11 +1272,14 @@ void lttng_consumer_set_command_sock_path(
  * 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) {
-               return lttcomm_send_unix_sock(ctx->consumer_error_socket, &cmd,
-                               sizeof(enum lttcomm_sessiond_command));
+               const int32_t comm_code = (int32_t) error_code;
+
+               return lttcomm_send_unix_sock(
+                       ctx->consumer_error_socket, &comm_code, sizeof(comm_code));
        }
 
        return 0;
index 7bfd28379802ec567804d1220ea3eead3d8e3e62..5026f70e41b9007a681ff35447d62120b2bd9076 100644 (file)
@@ -905,7 +905,8 @@ void lttng_consumer_set_command_sock_path(
  * 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.028732 seconds and 4 git commands to generate.