Fix: illegal memory access in enable_event
[lttng-tools.git] / src / bin / lttng-sessiond / agent.c
index ced0f85cf018c93d5ad1ac9a79a7e6c788ab136c..f79ac00e6f4c5313928d5a15bd560efbe41454d4 100644 (file)
@@ -408,17 +408,20 @@ static int enable_event(struct agent_app *app, struct agent_event *event)
        }
        data_size = sizeof(msg) + filter_expression_length;
 
-       ret = send_header(app->sock, data_size, AGENT_CMD_ENABLE, 0);
-       if (ret < 0) {
-               goto error_io;
-       }
-
        memset(&msg, 0, sizeof(msg));
        msg.loglevel_value = htobe32(event->loglevel_value);
        msg.loglevel_type = htobe32(event->loglevel_type);
-       strncpy(msg.name, event->name, sizeof(msg.name));
+       if (lttng_strncpy(msg.name, event->name, sizeof(msg.name))) {
+               ret = LTTNG_ERR_INVALID;
+               goto error;
+       }
        msg.filter_expression_length = htobe32(filter_expression_length);
 
+       ret = send_header(app->sock, data_size, AGENT_CMD_ENABLE, 0);
+       if (ret < 0) {
+               goto error_io;
+       }
+
        bytes_to_send = zmalloc(data_size);
        if (!bytes_to_send) {
                ret = LTTNG_ERR_NOMEM;
This page took 0.033368 seconds and 4 git commands to generate.