[lttng-dev] [BABELTRACE PATCH] Fix: safety checks for opening mmap traces

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Fri Aug 10 17:37:18 EDT 2012


* Julien Desfossez (jdesfossez at efficios.com) wrote:
> When adding a mmap trace in the context, we don't have any tracefile and
> index, some safety checks were missing in the path handling and
> timestamp manipulation.
> 
> Signed-off-by: Julien Desfossez <jdesfossez at efficios.com>

merged, thanks!

Mathieu

> ---
>  formats/ctf/ctf.c |    9 +++++++++
>  lib/context.c     |    6 ++++--
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
> index f33fa33..69917f7 100644
> --- a/formats/ctf/ctf.c
> +++ b/formats/ctf/ctf.c
> @@ -167,6 +167,9 @@ uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
>  			if (!stream_pos->packet_real_index)
>  				goto error;
>  
> +			if (stream_pos->packet_real_index->len <= 0)
> +				continue;
> +
>  			if (type == BT_CLOCK_REAL) {
>  				index = &g_array_index(stream_pos->packet_real_index,
>  						struct packet_index,
> @@ -225,6 +228,9 @@ uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
>  			if (!stream_pos->packet_real_index)
>  				goto error;
>  
> +			if (stream_pos->packet_real_index->len <= 0)
> +				continue;
> +
>  			if (type == BT_CLOCK_REAL) {
>  				index = &g_array_index(stream_pos->packet_real_index,
>  						struct packet_index,
> @@ -1845,6 +1851,9 @@ int ctf_convert_index_timestamp(struct trace_descriptor *tdp)
>  			stream_pos->packet_real_index = g_array_new(FALSE, TRUE,
>  					sizeof(struct packet_index));
>  
> +			if (!stream_pos->packet_cycles_index)
> +				continue;
> +
>  			for (k = 0; k < stream_pos->packet_cycles_index->len; k++) {
>  				struct packet_index *index;
>  				struct packet_index new_index;
> diff --git a/lib/context.c b/lib/context.c
> index 373944c..e2c1739 100644
> --- a/lib/context.c
> +++ b/lib/context.c
> @@ -104,8 +104,10 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
>  	}
>  	handle->format = fmt;
>  	handle->td = td;
> -	strncpy(handle->path, path, PATH_MAX);
> -	handle->path[PATH_MAX - 1] = '\0';
> +	if (path) {
> +		strncpy(handle->path, path, PATH_MAX);
> +		handle->path[PATH_MAX - 1] = '\0';
> +	}
>  
>  	if (fmt->set_handle)
>  		fmt->set_handle(td, handle);
> -- 
> 1.7.10.4
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list