From: Simon Marchi Date: Tue, 30 Nov 2021 03:15:53 +0000 (-0500) Subject: Fix: lttng: initialize variable in run_command_string X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=0b8afa0338a777bd61165a7699a12b8bd8ebe913;p=lttng-tools.git Fix: lttng: initialize variable in run_command_string 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 Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index e796aa97c..0ae1a6917 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -230,7 +230,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,