]> git.lttng.org Git - lttng-tools.git/commitdiff
Fix: lttng-ctl: Validate lttng_enable_event_with_exclusions inputs at beginning of...
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Nov 2024 14:41:18 +0000 (14:41 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2024 17:05:50 +0000 (17:05 +0000)
Checking for ev == nullptr after having dereferenced ev triggers this
Coverity warning:

    CID 1566411:  Null pointer dereferences  (REVERSE_INULL)
    Null-checking "ev" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.

Move the handle and ev nullptr checks before the LTTNG_EVENT_ALL
special-case. This is relevant because within LTTNG_EVENT_ALL, after
modifying the event type, lttng_enable_event_with_exclusions is invoked
again with the modified type, which will end up doing the input
validation anyway.

Move the original_filter_expression before the LTTNG_EVENT_ALL event
type check for the same reason: it will end up being checked with the
modified event type in the nested call anyway, so favor early checking
of input arguments.

Change-Id: Id1c931300aa49477a9f480698f5dad645240b904
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/lib/lttng-ctl/lttng-ctl.cpp

index cb2070c8221e11b054e87e50c7027c3418b3e273..029f0b0ef7722d3c3dcdbb5adc49156ce0bda20a 100644 (file)
@@ -1119,6 +1119,19 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
        lttng_payload payload;
        int ret = 0;
 
+       if (handle == nullptr || ev == nullptr) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       /*
+        * Empty filter string will always be rejected by the parser
+        * anyway, so treat this corner-case early to eliminate
+        * lttng_fmemopen error for 0-byte allocation.
+        */
+       if (original_filter_expression && strlen(original_filter_expression) == 0) {
+               return -LTTNG_ERR_INVALID;
+       }
+
        if (ev->type == LTTNG_EVENT_ALL) {
                /*
                 * Since we modify the user's parameter, ensure it is set back to its original value
@@ -1149,19 +1162,6 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
                return syscall_ret;
        }
 
-       if (handle == nullptr || ev == nullptr) {
-               return -LTTNG_ERR_INVALID;
-       }
-
-       /*
-        * Empty filter string will always be rejected by the parser
-        * anyway, so treat this corner-case early to eliminate
-        * lttng_fmemopen error for 0-byte allocation.
-        */
-       if (original_filter_expression && strlen(original_filter_expression) == 0) {
-               return -LTTNG_ERR_INVALID;
-       }
-
        /*
         * We have either a filter or some exclusions, so we need to set up
         * a variable-length payload from where to send the data.
This page took 0.030709 seconds and 4 git commands to generate.