Fix: sessiond: event name truncation during listing
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 12 Jan 2021 22:08:56 +0000 (17:08 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 12 Jan 2021 22:08:56 +0000 (17:08 -0500)
The use of strncpy can lead to silently-truncated event names. Replace
its use by the internal lttng_strncpy which fails on truncation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I65d6bd46208dc7b62a83e4600a52a6669fd99d55

src/bin/lttng-sessiond/cmd.c

index 2ae0ba687e89df721bb9cb96385f2685f6b00277..96f7433a6345fd90b1f608a272785fe3fc341578 100644 (file)
@@ -488,8 +488,14 @@ static int list_lttng_agent_events(struct agent *agt,
                        .loglevel_type = agent_event->loglevel_type,
                };
 
-               strncpy(event.name, agent_event->name, sizeof(event.name));
-               event.name[sizeof(event.name) - 1] = '\0';
+               ret = lttng_strncpy(event.name, agent_event->name, sizeof(event.name));
+               if (ret) {
+                       /* Internal error, invalid name. */
+                       ERR("Invalid event name while listing agent events: '%s' exceeds the maximal allowed length of %zu bytes",
+                                       agent_event->name, sizeof(event.name));
+                       ret = -LTTNG_ERR_UNK;
+                       goto end;
+               }
 
                ret = lttng_dynamic_buffer_append(
                                &payload->buffer, &event, sizeof(event));
@@ -556,8 +562,14 @@ static int list_lttng_ust_global_events(char *channel_name,
                        continue;
                }
 
-               strncpy(event.name, uevent->attr.name, sizeof(event.name));
-               event.name[sizeof(event.name) - 1] = '\0';
+               ret = lttng_strncpy(event.name, uevent->attr.name, sizeof(event.name));
+               if (ret) {
+                       /* Internal error, invalid name. */
+                       ERR("Invalid event name while listing user space tracer events: '%s' exceeds the maximal allowed length of %zu bytes",
+                                       uevent->attr.name, sizeof(event.name));
+                       ret = -LTTNG_ERR_UNK;
+                       goto end;
+               }
 
                event.enabled = uevent->enabled;
 
@@ -647,8 +659,16 @@ static int list_lttng_kernel_events(char *channel_name,
        cds_list_for_each_entry(kevent, &kchan->events_list.head , list) {
                struct lttng_event event = {};
 
-               strncpy(event.name, kevent->event->name, sizeof(event.name));
-               event.name[sizeof(event.name) - 1] = '\0';
+               ret = lttng_strncpy(event.name, kevent->event->name, sizeof(event.name));
+               if (ret) {
+                       /* Internal error, invalid name. */
+                       ERR("Invalid event name while listing kernel events: '%s' exceeds the maximal allowed length of %zu bytes",
+                                       kevent->event->name,
+                                       sizeof(event.name));
+                       ret = -LTTNG_ERR_UNK;
+                       goto end;
+               }
+
                event.enabled = kevent->enabled;
                event.filter = (unsigned char) !!kevent->filter_expression;
 
This page took 0.028203 seconds and 4 git commands to generate.