Fix: lttng: initialize variable in run_command_string
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 30 Nov 2021 03:15:53 +0000 (22:15 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 10 Jan 2022 23:43:51 +0000 (18:43 -0500)
I got some crashes when using `lttng track` and hitting some error
paths.  The tracker_handle variable is run_command_string is passed to
lttng_process_attr_tracker_handle_destroy uninitialized if
lttng_session_get_tracker_handle fails.

    $ valgrind lttng track --kernel --pid 569878
    ==634572== Memcheck, a memory error detector
    ==634572== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==634572== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
    ==634572== Command: lttng track --kernel --pid 569878
    ==634572==
    Error: Unknown error
    ==634572== Conditional jump or move depends on uninitialised value(s)
    ==634572==    at 0x4875007: lttng_process_attr_tracker_handle_destroy (tracker.cpp:25)
    ==634572==    by 0x13AC55: run_command_string(cmd_type, char const*, lttng_domain_type, lttng_process_attr, char const*, mi_writer*) (track-untrack.cpp:485)
    ==634572==    by 0x13ADA5: run_command(cmd_type, char const*, process_attr_command_args const*, mi_writer*) (track-untrack.cpp:535)
    ==634572==    by 0x13B472: cmd_track_untrack(cmd_type, int, char const**, char const*) (track-untrack.cpp:740)
    ==634572==    by 0x13B5D9: cmd_track(int, char const**) (track-untrack.cpp:805)
    ==634572==    by 0x14C598: handle_command(int, char**) (lttng.cpp:237)
    ==634572==    by 0x14CCE9: parse_args(int, char**) (lttng.cpp:426)
    ==634572==    by 0x14CE65: main (lttng.cpp:475)

Fix it by initializing it to NULL.

Change-Id: Id2693e75c3c5c83cef58db3109973d7ab679b859
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/track-untrack.cpp

index 7db44883bd49bda56f3cabf9521dd9c90dcf8a4f..59b6144232a3efe335d8e7eb980f7a9241573613 100644 (file)
@@ -229,7 +229,7 @@ static enum cmd_error_code run_command_string(enum cmd_type cmd_type,
                const char *_args,
                struct mi_writer *writer)
 {
-       struct lttng_process_attr_tracker_handle *tracker_handle;
+       struct lttng_process_attr_tracker_handle *tracker_handle = NULL;
        const enum lttng_error_code handle_ret_code =
                        lttng_session_get_tracker_handle(session_name,
                                        domain_type, process_attr,
This page took 0.027619 seconds and 4 git commands to generate.