Fix: sessiond: trace-kernel: function return code overwritten
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 9 Feb 2021 21:04:05 +0000 (16:04 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 9 Feb 2021 23:39:30 +0000 (18:39 -0500)
A string copy, performed using `lttng_strncpy` is performed at the end
of trace_kernel_init_event_notifier_from_event_rule() and its return
value is stored in the function's `ret` variable, which is of type `enum
lttng_error_code`.

Since LTTNG_OK is not == 0, the return value is interpreted as an error,
which causes the registration of kernel-domain on-event-hit triggers
to fail.

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

src/bin/lttng-sessiond/trace-kernel.c

index 6e8a8b2debebb525250075e5ebdb0eb55f3b9069..7dde1b51d0cef1862f36b1fc4d3afb6e6bce9144 100644 (file)
@@ -545,8 +545,9 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                const struct lttng_event_rule *rule,
                struct lttng_kernel_event_notifier *kernel_event_notifier)
 {
-       enum lttng_error_code ret;
+       enum lttng_error_code ret_code;
        const char *name;
+       int strncpy_ret;
 
        switch (lttng_event_rule_get_type(rule)) {
        case LTTNG_EVENT_RULE_TYPE_KPROBE:
@@ -559,7 +560,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
 
                status = lttng_event_rule_kprobe_get_location(rule, &location);
                if (status != LTTNG_EVENT_RULE_STATUS_OK) {
-                       ret = LTTNG_ERR_PROBE_LOCATION_INVAL;
+                       ret_code = LTTNG_ERR_PROBE_LOCATION_INVAL;
                        goto error;
                }
 
@@ -588,12 +589,12 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                kernel_event_notifier->event.u.kprobe.addr = address;
                kernel_event_notifier->event.u.kprobe.offset = offset;
                if (symbol_name) {
-                       const int copy_ret = lttng_strncpy(
+                       strncpy_ret = lttng_strncpy(
                                        kernel_event_notifier->event.u.kprobe.symbol_name,
                                        symbol_name, LTTNG_KERNEL_SYM_NAME_LEN);
 
-                       if (copy_ret) {
-                               ret = LTTNG_ERR_INVALID;
+                       if (strncpy_ret) {
+                               ret_code = LTTNG_ERR_INVALID;
                                goto error;
                        }
                }
@@ -601,7 +602,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                kernel_event_notifier->event.u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                status = lttng_event_rule_kprobe_get_name(rule, &name);
                assert(status == LTTNG_EVENT_RULE_STATUS_OK);
-               ret = LTTNG_OK;
+               ret_code = LTTNG_OK;
                break;
        }
        case LTTNG_EVENT_RULE_TYPE_UPROBE:
@@ -612,7 +613,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
 
                status = lttng_event_rule_uprobe_get_location(rule, &location);
                if (status != LTTNG_EVENT_RULE_STATUS_OK) {
-                       ret = LTTNG_ERR_PROBE_LOCATION_INVAL;
+                       ret_code = LTTNG_ERR_PROBE_LOCATION_INVAL;
                        goto error;
                }
 
@@ -621,7 +622,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                lookup = lttng_userspace_probe_location_get_lookup_method(
                                location);
                if (!lookup) {
-                       ret = LTTNG_ERR_PROBE_LOCATION_INVAL;
+                       ret_code = LTTNG_ERR_PROBE_LOCATION_INVAL;
                        goto error;
                }
 
@@ -647,7 +648,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
 
                status = lttng_event_rule_uprobe_get_name(rule, &name);
                assert(status == LTTNG_EVENT_RULE_STATUS_OK);
-               ret = LTTNG_OK;
+               ret_code = LTTNG_OK;
                break;
        }
        case LTTNG_EVENT_RULE_TYPE_TRACEPOINT:
@@ -663,7 +664,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                kernel_event_notifier->event.instrumentation =
                                LTTNG_KERNEL_TRACEPOINT;
 
-               ret = LTTNG_OK;
+               ret_code = LTTNG_OK;
                break;
        }
        case LTTNG_EVENT_RULE_TYPE_SYSCALL:
@@ -682,7 +683,7 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                                LTTNG_KERNEL_SYSCALL_ENTRY;
                kernel_event_notifier->event.u.syscall.match =
                                LTTNG_KERNEL_SYSCALL_MATCH_NAME;
-               ret = LTTNG_OK;
+               ret_code = LTTNG_OK;
                break;
        }
        case LTTNG_EVENT_RULE_TYPE_KRETPROBE:
@@ -691,15 +692,15 @@ enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
                break;
        }
 
-       ret = lttng_strncpy(kernel_event_notifier->event.name, name,
+       strncpy_ret = lttng_strncpy(kernel_event_notifier->event.name, name,
                        LTTNG_KERNEL_SYM_NAME_LEN);
-       if (ret) {
-               ret = LTTNG_ERR_INVALID;
+       if (strncpy_ret) {
+               ret_code = LTTNG_ERR_INVALID;
                goto error;
        }
 
 error:
-       return ret;
+       return ret_code;
 }
 /*
  * Allocate and initialize a kernel metadata.
This page took 0.036748 seconds and 4 git commands to generate.