Fix: liblttng-ctl comm: lttng_event_field is not packed
[lttng-tools.git] / src / bin / lttng-sessiond / client.c
index 0d56e42f5da6cd70a1b7ab26a8aa5d3339e21980..3563811421359ea43331e8fd8babc535a90cd1d1 100644 (file)
@@ -981,74 +981,7 @@ skip_domain:
        switch (cmd_ctx->lsm->cmd_type) {
        case LTTNG_ADD_CONTEXT:
        {
-               /*
-                * An LTTNG_ADD_CONTEXT command might have a supplementary
-                * payload if the context being added is an application context.
-                */
-               if (cmd_ctx->lsm->u.context.ctx.ctx ==
-                               LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
-                       char *provider_name = NULL, *context_name = NULL;
-                       size_t provider_name_len =
-                                       cmd_ctx->lsm->u.context.provider_name_len;
-                       size_t context_name_len =
-                                       cmd_ctx->lsm->u.context.context_name_len;
-
-                       if (provider_name_len == 0 || context_name_len == 0) {
-                               /*
-                                * Application provider and context names MUST
-                                * be provided.
-                                */
-                               ret = -LTTNG_ERR_INVALID;
-                               goto error;
-                       }
-
-                       provider_name = zmalloc(provider_name_len + 1);
-                       if (!provider_name) {
-                               ret = -LTTNG_ERR_NOMEM;
-                               goto error;
-                       }
-                       cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name =
-                                       provider_name;
-
-                       context_name = zmalloc(context_name_len + 1);
-                       if (!context_name) {
-                               ret = -LTTNG_ERR_NOMEM;
-                               goto error_add_context;
-                       }
-                       cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name =
-                                       context_name;
-
-                       ret = lttcomm_recv_unix_sock(*sock, provider_name,
-                                       provider_name_len);
-                       if (ret < 0) {
-                               goto error_add_context;
-                       }
-
-                       ret = lttcomm_recv_unix_sock(*sock, context_name,
-                                       context_name_len);
-                       if (ret < 0) {
-                               goto error_add_context;
-                       }
-               }
-
-               /*
-                * cmd_add_context assumes ownership of the provider and context
-                * names.
-                */
-               ret = cmd_add_context(cmd_ctx->session,
-                               cmd_ctx->lsm->domain.type,
-                               cmd_ctx->lsm->u.context.channel_name,
-                               ALIGNED_CONST_PTR(cmd_ctx->lsm->u.context.ctx),
-                               kernel_poll_pipe[1]);
-
-               cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name = NULL;
-               cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name = NULL;
-error_add_context:
-               free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name);
-               free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name);
-               if (ret < 0) {
-                       goto error;
-               }
+               ret = cmd_add_context(cmd_ctx, *sock, kernel_poll_pipe[1]);
                break;
        }
        case LTTNG_DISABLE_CHANNEL:
@@ -1290,26 +1223,28 @@ error_add_context:
        }
        case LTTNG_LIST_TRACEPOINT_FIELDS:
        {
-               struct lttng_event_field *fields;
-               ssize_t nb_fields;
+               enum lttng_error_code ret_code;
+               unsigned int nb_fields;
+               struct lttcomm_list_command_header cmd_header;
 
                session_lock_list();
-               nb_fields = cmd_list_tracepoint_fields(cmd_ctx->lsm->domain.type,
-                               &fields);
+               ret_code = cmd_list_tracepoint_fields(
+                               cmd_ctx->lsm->domain.type, &payload, &nb_fields);
                session_unlock_list();
-               if (nb_fields < 0) {
-                       /* Return value is a negative lttng_error_code. */
-                       ret = -nb_fields;
+               if (ret_code != LTTNG_OK) {
+                       ret = (int) ret_code;
                        goto error;
                }
 
-               /*
-                * Setup lttng message with payload size set to the event list size in
-                * bytes and then copy list into the llm payload.
-                */
-               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, fields,
-                               sizeof(struct lttng_event_field) * nb_fields);
-               free(fields);
+               if (nb_fields > UINT32_MAX) {
+                       ret = LTTNG_ERR_OVERFLOW;
+                       goto error;
+               }
+
+               cmd_header.count = nb_fields;
+
+               ret = setup_lttng_msg(cmd_ctx, payload.data, payload.size,
+                               &cmd_header, sizeof(cmd_header));
 
                if (ret < 0) {
                        goto setup_error;
This page took 0.023965 seconds and 4 git commands to generate.