[lttng-dev] [PATCH lttng-tools] Fix: systematic overwrite of union values on add context

Jérémie Galarneau jeremie.galarneau at efficios.com
Sat Mar 12 18:35:01 UTC 2016


On Thu, Mar 10, 2016 at 3:04 PM, Jonathan Rajotte
<jonathan.rajotte-julien at efficios.com> wrote:
> Bug introduced in commit 2001793c1141e89b34e70efb28b27ec0cc8e6d47
>
> The type and config fields of the lttng_event_perf_counter_ctx member of
> lttng_event_context union would always be set to zero.
>
> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> ---
>  src/lib/lttng-ctl/lttng-ctl.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c
> index fe0527d..436f358 100644
> --- a/src/lib/lttng-ctl/lttng-ctl.c
> +++ b/src/lib/lttng-ctl/lttng-ctl.c
> @@ -736,9 +736,15 @@ int lttng_add_context(struct lttng_handle *handle,
>                 memcpy(buf + provider_len, ctx_name, ctx_len);
>         }
>         memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
> -       /* Don't leak application addresses to the sessiond. */
> -       lsm.u.context.ctx.u.app_ctx.provider_name = NULL;
> -       lsm.u.context.ctx.u.app_ctx.ctx_name = NULL;
> +
> +       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
> +               /* Don't leak application addresses to the sessiond.
> +                * This is only necessary when ctx is for an app ctx otherwise
> +                * the value inside the union (type & config) are overwritten.
> +                */

Good catch! Merged in master, thanks!

I changed the multi-line comment to the form:

/* (leave this line empty)
 * Blah.
 */

Jérémie

> +               lsm.u.context.ctx.u.app_ctx.provider_name = NULL;
> +               lsm.u.context.ctx.u.app_ctx.ctx_name = NULL;
> +       }
>
>         ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL);
>  end:
> --
> 2.7.0
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list