From: Jonathan Rajotte Date: Wed, 2 Mar 2022 15:50:16 +0000 (-0500) Subject: Fix: event: unchecked return value for lttng_strncpy X-Git-Tag: v2.12.9~19 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=38128370a845ede158a9e8793f6836cb220240af;p=lttng-tools.git Fix: event: unchecked return value for lttng_strncpy Reported by Coverity: CID 1475806: Unchecked return value (CHECKED_RETURN) Calling lttng_strncpy without checking return value. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Ib2b16bef61bcc24fea381c18fd8f914e9a84a6e7 --- diff --git a/src/common/event.c b/src/common/event.c index fd44f6da2..56af0caaa 100644 --- a/src/common/event.c +++ b/src/common/event.c @@ -1054,7 +1054,8 @@ static ssize_t lttng_event_context_perf_counter_populate_from_buffer( const struct lttng_buffer_view *view, struct lttng_event_context *event_ctx) { - ssize_t ret, offset = 0; + int ret; + ssize_t consumed, offset = 0; const struct lttng_event_context_perf_counter_comm *comm; size_t name_len; const struct lttng_buffer_view comm_view = lttng_buffer_view_from_view( @@ -1066,7 +1067,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_buffer( event_ctx->ctx == LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER); if (!lttng_buffer_view_is_valid(&comm_view)) { - ret = -1; + consumed = -1; goto end; } @@ -1080,7 +1081,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_buffer( lttng_buffer_view_from_view( view, offset, name_len); if (!lttng_buffer_view_is_valid(&provider_name_view)) { - ret = -1; + consumed = -1; goto end; } @@ -1088,21 +1089,25 @@ static ssize_t lttng_event_context_perf_counter_populate_from_buffer( if (!lttng_buffer_view_contains_string( &provider_name_view, name, name_len)) { - ret = -1; + consumed = -1; goto end; } - lttng_strncpy(event_ctx->u.perf_counter.name, name, name_len); + ret = lttng_strncpy(event_ctx->u.perf_counter.name, name, name_len); + if (ret) { + consumed = -1; + goto end; + } offset += name_len; } event_ctx->u.perf_counter.config = comm->config; event_ctx->u.perf_counter.type = comm->type; - ret = offset; + consumed = offset; end: - return ret; + return consumed; } LTTNG_HIDDEN