From: Jérémie Galarneau Date: Sun, 23 Nov 2014 16:30:33 +0000 (-0500) Subject: Fix: Handle empty daemon configuration file lines X-Git-Tag: v2.6.0-rc4~35 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bc26aefd3834ed8b5cf0b8c2c1504ac24bd6ee77;p=lttng-tools.git Fix: Handle empty daemon configuration file lines Empty daemon configuration file lines such as my_option= will cause set_option to be called with an arg value of length 0 which should display a warning. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 3910f4fd3..590df85b6 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -4256,6 +4256,17 @@ static int set_option(int opt, const char *arg, const char *optname) { int ret = 0; + if (arg && arg[0] == '\0') { + /* + * This only happens if the value is read from daemon config + * file. This means the option requires an argument and the + * configuration file contains a line such as: + * my_option = + */ + ret = -EINVAL; + goto end; + } + switch (opt) { case 0: fprintf(stderr, "option %s", optname); @@ -4447,6 +4458,22 @@ static int set_option(int opt, const char *arg, const char *optname) ret = -1; } + if (ret == -EINVAL) { + const char *opt_name = "unknown"; + int i; + + for (i = 0; i < sizeof(long_options) / sizeof(struct option); + i++) { + if (opt == long_options[i].val) { + opt_name = long_options[i].name; + break; + } + } + + WARN("Invalid argument provided for option \"%s\", using default value.", + opt_name); + } +end: return ret; }