From cc7a411fc5a4e62c9211b882095ddde98640d63b Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Wed, 1 Aug 2018 17:22:47 +0200 Subject: [PATCH] util/ectool: Handle arguments more carefully Check if an argument is given and if not print the usage. Check if all arguments are handled by getopt and if not print the usage. Change-Id: I40dbd2a51d018eb549e9b2fa4365b3e4f9355bff Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/27778 Tested-by: build bot (Jenkins) Reviewed-by: Alexander Couzens Reviewed-by: Evgeny Zinoviev --- util/ectool/ectool.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/ectool/ectool.c b/util/ectool/ectool.c index be5a899765..bc3d46cd52 100644 --- a/util/ectool/ectool.c +++ b/util/ectool/ectool.c @@ -90,6 +90,11 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; + if (argv[1] == NULL) { + print_usage(argv[0]); + exit(1); + } + while ((opt = getopt_long(argc, argv, "vh?Vidqpw:z:", long_options, &option_index)) != EOF) { switch (opt) { @@ -128,6 +133,12 @@ int main(int argc, char *argv[]) } } + if (optind < argc) { + fprintf(stderr, "Error: Extra parameter found.\n"); + print_usage(argv[0]); + exit(1); + } + if (get_ports && get_ec_ports() != 0) fprintf(stderr, "Cannot get EC ports from /proc/ioports, " "fallback to default.");