From: Jérémie Galarneau Date: Thu, 26 Mar 2015 19:07:35 +0000 (-0400) Subject: Fix: possible use of uninitialized data in loglevel conversion funcs X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=3712b11040b3b8a880de825584f817a376865564 Fix: possible use of uninitialized data in loglevel conversion funcs str will be uninitialized if inputstr[0] == '\0' Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 92ca76272..1b3d5f7cd 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -334,6 +334,10 @@ static int loglevel_log4j_str_to_value(const char *inputstr) int i = 0; char str[LTTNG_SYMBOL_NAME_LEN]; + if (!inputstr || strlen(inputstr) == 0) { + return -1; + } + /* * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is * added at the end of the loop so a the upper bound we avoid the overflow. @@ -373,6 +377,10 @@ static int loglevel_jul_str_to_value(const char *inputstr) int i = 0; char str[LTTNG_SYMBOL_NAME_LEN]; + if (!inputstr || strlen(inputstr) == 0) { + return -1; + } + /* * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is * added at the end of the loop so a the upper bound we avoid the overflow. @@ -414,6 +422,10 @@ static int loglevel_python_str_to_value(const char *inputstr) int i = 0; char str[LTTNG_SYMBOL_NAME_LEN]; + if (!inputstr || strlen(inputstr) == 0) { + return -1; + } + /* * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is * added at the end of the loop so a the upper bound we avoid the overflow. @@ -450,6 +462,10 @@ int loglevel_str_to_value(const char *inputstr) int i = 0; char str[LTTNG_SYMBOL_NAME_LEN]; + if (!inputstr || strlen(inputstr) == 0) { + return -1; + } + /* * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is * added at the end of the loop so a the upper bound we avoid the overflow.