Fix: event: unchecked return value for lttng_strncpy
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 2 Mar 2022 15:50:16 +0000 (10:50 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 3 Mar 2022 16:03:58 +0000 (11:03 -0500)
Reported by Coverity:

  CID 1475806: Unchecked return value (CHECKED_RETURN)
  Calling lttng_strncpy without checking return value.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib2b16bef61bcc24fea381c18fd8f914e9a84a6e7

src/common/event.c

index 785430944525ae8bf8f119aa0e1e9f0eb9f2f6b9..0d6a60fbaab83fd237b4ebfd354f367191e0f877 100644 (file)
@@ -998,7 +998,8 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                const struct lttng_payload_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(
@@ -1010,7 +1011,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                        event_ctx->ctx == LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER);
 
        if (!lttng_buffer_view_is_valid(&comm_view)) {
-               ret = -1;
+               consumed = -1;
                goto end;
        }
 
@@ -1027,7 +1028,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                                                name_len);
 
                if (!lttng_buffer_view_is_valid(&provider_name_view)) {
-                       ret = -1;
+                       consumed = -1;
                        goto end;
                }
 
@@ -1035,21 +1036,25 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
 
                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;
 }
 
 ssize_t lttng_event_context_create_from_payload(
This page took 0.032265 seconds and 4 git commands to generate.