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:21:10 +0000 (12:21 -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 093944c8e397198025b2be515e1aaabbabd036ce..8f0dde185bd9d7bf58c07f88bfe8392c9a8fc5b7 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 a2df6c9587b5b047f6c71a286d3973f3a248f1f1..f5c532714cdedfd8f624295d2274a5402e96b640 100644 (file)
@@ -1269,11 +1269,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 53c39e6eb003e9530050de53e276f7ef1672fe05..6455692968d8f7a49f04c9a37fbeeecb7f5ecbf2 100644 (file)
@@ -918,7 +918,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.029409 seconds and 4 git commands to generate.