From 441c16a7f0bbab56a5e783059d0cddab68544a9a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 6 Feb 2012 21:50:16 -0500 Subject: [PATCH] Initialize all stack variables to zero, fix uninitialized loglevel variables If we want the padding behavior to be always the same (for future extensibility), we need to set those variables to zero when they are declared on the stack. Also fix uninitialized loglevel variables in tests, which were failing on x86_32 due to this. Signed-off-by: Mathieu Desnoyers --- src/bin/lttng/commands/add_context.c | 3 +++ src/bin/lttng/commands/calibrate.c | 3 +++ src/bin/lttng/commands/disable_channels.c | 2 ++ src/bin/lttng/commands/disable_events.c | 2 ++ src/bin/lttng/commands/enable_channels.c | 2 ++ src/bin/lttng/commands/enable_events.c | 3 +++ src/bin/lttng/commands/list.c | 6 ++++++ src/lib/lttng-ctl/lttng-ctl.c | 18 +++++++++++++++--- tests/lttng/kernel_all_events_basic.c | 15 ++++++++------- tests/lttng/kernel_event_basic.c | 19 +++++++++++++------ tests/lttng/ust_global_all_events_basic.c | 14 +++++++------- tests/lttng/ust_global_event_basic.c | 15 +++++++++------ tests/test_kernel_data_trace.c | 4 ++++ tests/test_ust_data_trace.c | 4 ++++ 14 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index ed4f87fb4..e499ef3d3 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -369,6 +369,9 @@ static int add_context(char *session_name) struct ctx_type *type; char *ptr; + memset(&context, 0, sizeof(context)); + memset(&dom, 0, sizeof(dom)); + if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index dc95d2469..61b588e12 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -127,6 +127,9 @@ static int calibrate_lttng(void) struct lttng_domain dom; struct lttng_calibrate calibrate; + memset(&dom, 0, sizeof(dom)); + memset(&calibrate, 0, sizeof(calibrate)); + /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index ccd5446db..cfc8561d9 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -92,6 +92,8 @@ static int disable_channels(char *session_name) char *channel_name; struct lttng_domain dom; + memset(&dom, 0, sizeof(dom)); + /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index b30ec1fdc..0a9c833bb 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -100,6 +100,8 @@ static int disable_events(char *session_name) char *event_name, *channel_name = NULL; struct lttng_domain dom; + memset(&dom, 0, sizeof(dom)); + /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 692480e81..91345e051 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -155,6 +155,8 @@ static int enable_channel(char *session_name) char *channel_name; struct lttng_domain dom; + memset(&dom, 0, sizeof(dom)); + /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index e8f55dc75..6fe393fb6 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -285,6 +285,9 @@ static int enable_events(char *session_name) struct lttng_event ev; struct lttng_domain dom; + memset(&ev, 0, sizeof(ev)); + memset(&dom, 0, sizeof(dom)); + /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index e4ab97cbe..b73d5209f 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -246,6 +246,8 @@ static int list_ust_events(void) struct lttng_event *event_list; pid_t cur_pid = 0; + memset(&domain, 0, sizeof(domain)); + DBG("Getting UST tracing events"); domain.type = LTTNG_DOMAIN_UST; @@ -295,6 +297,8 @@ static int list_kernel_events(void) struct lttng_handle *handle; struct lttng_event *event_list; + memset(&domain, 0, sizeof(domain)); + DBG("Getting kernel tracing events"); domain.type = LTTNG_DOMAIN_KERNEL; @@ -556,6 +560,8 @@ int cmd_list(int argc, const char **argv) struct lttng_domain domain; struct lttng_domain *domains = NULL; + memset(&domain, 0, sizeof(domain)); + if (argc < 1) { usage(stderr); ret = CMD_ERROR; diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 1d92facf0..dafe085dc 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -74,6 +74,7 @@ static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src memcpy(dst, src, sizeof(struct lttng_domain)); break; default: + memset(dst, 0, sizeof(struct lttng_domain)); dst->type = LTTNG_DOMAIN_KERNEL; break; } @@ -484,6 +485,8 @@ int lttng_add_context(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_ADD_CONTEXT; /* Copy channel name */ @@ -518,6 +521,8 @@ int lttng_enable_event(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + /* If no channel name, we put the default name */ if (channel_name == NULL) { copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, @@ -557,6 +562,8 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name, return -1; } + memset(&lsm, 0, sizeof(lsm)); + if (channel_name) { copy_string(lsm.u.disable.channel_name, channel_name, sizeof(lsm.u.disable.channel_name)); @@ -596,6 +603,8 @@ int lttng_enable_channel(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan)); lsm.cmd_type = LTTNG_ENABLE_CHANNEL; @@ -621,6 +630,8 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name) return -1; } + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_DISABLE_CHANNEL; copy_string(lsm.u.disable.channel_name, name, @@ -861,11 +872,13 @@ int lttng_calibrate(struct lttng_handle *handle, /* * Set default channel attributes. - * If either or both of the arguments are null, nothing happens. + * If either or both of the arguments are null, attr content is zeroe'd. */ void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr) { + memset(attr, 0, sizeof(struct lttng_channel_attr)); + /* Safety check */ if (attr == NULL || domain == NULL) { return; @@ -896,8 +909,7 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, attr->output = DEFAULT_UST_CHANNEL_OUTPUT; break; default: - /* Default behavior */ - memset(attr, 0, sizeof(struct lttng_channel_attr)); + /* Default behavior: leave set to 0. */ break; } } diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/lttng/kernel_all_events_basic.c index 79c2b66ac..3e12f00f1 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/lttng/kernel_all_events_basic.c @@ -31,17 +31,18 @@ int main(int argc, char **argv) { - struct lttng_handle *handle = NULL; - struct lttng_domain dom; + struct lttng_handle *handle = NULL; + struct lttng_domain dom; struct lttng_event event; - char *channel_name = "channel0"; + char *channel_name = "channel0"; char *session_name = "kernel_all_events_basic"; - int ret = 0; + int ret = 0; - dom.type = LTTNG_DOMAIN_KERNEL; - - memset(&event, 0, sizeof(struct lttng_event)); + memset(&dom, 0, sizeof(dom)); + memset(&event, 0, sizeof(event)); + dom.type = LTTNG_DOMAIN_KERNEL; event.type = LTTNG_EVENT_TRACEPOINT; + event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("\nTesting tracing all kernel events:\n"); printf("-----------\n"); diff --git a/tests/lttng/kernel_event_basic.c b/tests/lttng/kernel_event_basic.c index fb1cf42b0..6a11331ba 100644 --- a/tests/lttng/kernel_event_basic.c +++ b/tests/lttng/kernel_event_basic.c @@ -31,18 +31,22 @@ int main(int argc, char **argv) { - struct lttng_handle *handle = NULL; - struct lttng_domain dom; + struct lttng_handle *handle = NULL; + struct lttng_domain dom; struct lttng_channel channel; struct lttng_event sched_switch; struct lttng_event sched_process_exit; struct lttng_event sched_process_free; - - int ret = 0; - char *session_name = "kernel_event_basic"; + int ret = 0; + + memset(&dom, 0, sizeof(dom)); + memset(&channel, 0, sizeof(channel)); + memset(&sched_switch, 0, sizeof(sched_switch)); + memset(&sched_process_exit, 0, sizeof(sched_process_exit)); + memset(&sched_process_free, 0, sizeof(sched_process_free)); - dom.type = LTTNG_DOMAIN_KERNEL; + dom.type = LTTNG_DOMAIN_KERNEL; strcpy(channel.name, "mychan"); channel.attr.overwrite = 0; @@ -54,12 +58,15 @@ int main(int argc, char **argv) strcpy(sched_switch.name, "sched_switch"); sched_switch.type = LTTNG_EVENT_TRACEPOINT; + sched_switch.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; strcpy(sched_process_exit.name, "sched_process_exit"); sched_process_exit.type = LTTNG_EVENT_TRACEPOINT; + sched_process_exit.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; strcpy(sched_process_free.name, "sched_process_free"); sched_process_free.type = LTTNG_EVENT_TRACEPOINT; + sched_process_free.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("\nTesting tracing kernel events:\n"); printf("-----------\n"); diff --git a/tests/lttng/ust_global_all_events_basic.c b/tests/lttng/ust_global_all_events_basic.c index 56746a73f..968dd9a6c 100644 --- a/tests/lttng/ust_global_all_events_basic.c +++ b/tests/lttng/ust_global_all_events_basic.c @@ -31,16 +31,16 @@ int main(int argc, char **argv) { - struct lttng_handle *handle = NULL; - struct lttng_domain dom; + struct lttng_handle *handle = NULL; + struct lttng_domain dom; struct lttng_event event; - char *channel_name = "channel0"; + char *channel_name = "channel0"; char *session_name = "ust_global_all_events_basic"; - int ret = 0; + int ret = 0; - dom.type = LTTNG_DOMAIN_UST; - - memset(&event, 0, sizeof(struct lttng_event)); + memset(&dom, 0, sizeof(dom)); + memset(&event, 0, sizeof(event)); + dom.type = LTTNG_DOMAIN_UST; event.type = LTTNG_EVENT_TRACEPOINT; event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; diff --git a/tests/lttng/ust_global_event_basic.c b/tests/lttng/ust_global_event_basic.c index 5a7af53e2..2e05fffe5 100644 --- a/tests/lttng/ust_global_event_basic.c +++ b/tests/lttng/ust_global_event_basic.c @@ -31,17 +31,20 @@ int main(int argc, char **argv) { - struct lttng_handle *handle = NULL; - struct lttng_domain dom; + struct lttng_handle *handle = NULL; + struct lttng_domain dom; struct lttng_channel channel; struct lttng_event ev1, ev2, ev3; - - int ret = 0; - char *session_name = "ust_global_event_basic"; + int ret = 0; - dom.type = LTTNG_DOMAIN_UST; + memset(&dom, 0, sizeof(dom)); + memset(&channel, 0, sizeof(channel)); + memset(&ev1, 0, sizeof(ev1)); + memset(&ev2, 0, sizeof(ev2)); + memset(&ev3, 0, sizeof(ev3)); + dom.type = LTTNG_DOMAIN_UST; strcpy(channel.name, "mychan"); channel.attr.overwrite = 0; channel.attr.subbuf_size = 4096; diff --git a/tests/test_kernel_data_trace.c b/tests/test_kernel_data_trace.c index 6dba1f523..bfc0f41af 100644 --- a/tests/test_kernel_data_trace.c +++ b/tests/test_kernel_data_trace.c @@ -117,6 +117,8 @@ static void create_kernel_channel(void) struct ltt_kernel_channel *chan; struct lttng_channel attr; + memset(&attr, 0, sizeof(attr)); + printf("Creating kernel channel: "); chan = trace_kernel_create_channel(&attr, PATH1); assert(chan != NULL); @@ -141,8 +143,10 @@ static void create_kernel_event(void) struct ltt_kernel_event *event; struct lttng_event ev; + memset(&ev, 0, sizeof(ev)); strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN); ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("Creating kernel event: "); event = trace_kernel_create_event(&ev); diff --git a/tests/test_ust_data_trace.c b/tests/test_ust_data_trace.c index 4547b49a2..6acd7a0d0 100644 --- a/tests/test_ust_data_trace.c +++ b/tests/test_ust_data_trace.c @@ -122,6 +122,8 @@ static void create_ust_channel(void) struct ltt_ust_channel *uchan; struct lttng_channel attr; + memset(&attr, 0, sizeof(attr)); + strncpy(attr.name, "channel0", 8); printf("Creating UST channel: "); @@ -147,8 +149,10 @@ static void create_ust_event(void) struct ltt_ust_event *event; struct lttng_event ev; + memset(&ev, 0, sizeof(ev)); strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("Creating UST event: "); event = trace_ust_create_event(&ev); -- 2.34.1