From 28be3820196648129d73bd431c71b36c130f5cc2 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sat, 11 Aug 2012 20:56:41 +0200 Subject: [PATCH] conf: make missing arguments or wrong arguments fatal It is not acceptable to start the applications with wrong parameters. A typo must be corrected before starting the application so simply fail loudly on errors. Signed-off-by: David Herrmann --- src/conf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 8267e30..426da14 100644 --- a/src/conf.c +++ b/src/conf.c @@ -299,6 +299,7 @@ int conf_parse_argv(int argc, char **argv) } else if (c == ':') { fprintf(stderr, "Missing argument for option %s\n", argv[optind - 1]); + return -EFAULT; } else if (c == '?') { if (optopt) fprintf(stderr, "Unknown argument -%c\n", @@ -306,6 +307,7 @@ int conf_parse_argv(int argc, char **argv) else fprintf(stderr, "Unknown argument %s\n", argv[optind - 1]); + return -EFAULT; } else if (c < 100000) { for (i = 0; i < len; ++i) { if (options[i].short_name == c) { @@ -353,8 +355,10 @@ int conf_parse_argv(int argc, char **argv) } else { def_argv[0] = getenv("SHELL") ? : _PATH_BSHELL; conf_global.argv = def_argv; - if (optind != argc) + if (optind != argc) { fprintf(stderr, "Unparsed remaining arguments\n"); + return -EFAULT; + } } /* --debug implies --verbose */