From 9cd9d98300af3039db7f146a47914baef2e8ea1b Mon Sep 17 00:00:00 2001 From: Enrico Jorns Date: Mon, 12 Sep 2016 12:20:56 +0200 Subject: commands: exit on invalid option Barebox commands should not perform any action and return 0 if an invalid parameter was given. This might cause undetected unintended behvaior when calling commands with wrong options, either manually or from a script. Signed-off-by: Enrico Jorns Signed-off-by: Sascha Hauer --- commands/boot.c | 2 ++ commands/bootm.c | 2 +- commands/dhcp.c | 2 ++ commands/fbtest.c | 2 ++ commands/hashsum.c | 2 ++ commands/help.c | 2 ++ commands/hwclock.c | 2 ++ commands/linux16.c | 2 ++ commands/loadb.c | 3 +-- commands/loadxy.c | 3 +-- commands/ls.c | 2 ++ commands/mem.c | 2 +- commands/menutree.c | 2 ++ commands/reset.c | 2 ++ commands/splash.c | 2 ++ commands/usb.c | 2 ++ commands/usbserial.c | 2 ++ 17 files changed, 30 insertions(+), 6 deletions(-) diff --git a/commands/boot.c b/commands/boot.c index 8b3b407e12..102ca07980 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -53,6 +53,8 @@ static int do_boot(int argc, char *argv[]) case 'w': boot_set_watchdog_timeout(simple_strtoul(optarg, NULL, 0)); break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/bootm.c b/commands/bootm.c index 61b9086a15..c7cbdbe0f4 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -97,7 +97,7 @@ static int do_bootm(int argc, char *argv[]) data.dryrun = 1; break; default: - break; + return COMMAND_ERROR_USAGE; } } diff --git a/commands/dhcp.c b/commands/dhcp.c index eb98bfc2a7..4f4f5490c5 100644 --- a/commands/dhcp.c +++ b/commands/dhcp.c @@ -45,6 +45,8 @@ static int do_dhcp(int argc, char *argv[]) case 'r': retries = simple_strtoul(optarg, NULL, 10); break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/fbtest.c b/commands/fbtest.c index d070d1f7ab..bd0e140d07 100644 --- a/commands/fbtest.c +++ b/commands/fbtest.c @@ -137,6 +137,8 @@ static int do_fbtest(int argc, char *argv[]) case 'c': color = simple_strtoul(optarg, NULL, 16); break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/hashsum.c b/commands/hashsum.c index d05e571fb9..70aab2c4bf 100644 --- a/commands/hashsum.c +++ b/commands/hashsum.c @@ -42,6 +42,8 @@ static int do_hash(char *algo, int argc, char *argv[]) key = optarg; keylen = strlen(key); break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/help.c b/commands/help.c index 3d36d9bf48..819c40653c 100644 --- a/commands/help.c +++ b/commands/help.c @@ -98,6 +98,8 @@ static int do_help(int argc, char *argv[]) case 'a': all = 1; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/hwclock.c b/commands/hwclock.c index 6a0fe0342a..5073618675 100644 --- a/commands/hwclock.c +++ b/commands/hwclock.c @@ -123,6 +123,8 @@ static int do_hwclock(int argc, char *argv[]) ntp_to_hw = 1; ntpserver = optarg; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/linux16.c b/commands/linux16.c index bb678bdb83..db8d08105f 100644 --- a/commands/linux16.c +++ b/commands/linux16.c @@ -176,6 +176,8 @@ static int do_linux16(int argc, char *argv[]) } } break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/loadb.c b/commands/loadb.c index 6180ce371a..8c3906ca42 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -634,8 +634,7 @@ static int do_load_serial_bin(int argc, char *argv[]) console_dev_name = optarg; break; default: - perror(argv[0]); - return 1; + return COMMAND_ERROR_USAGE; } } diff --git a/commands/loadxy.c b/commands/loadxy.c index a4b1bec94d..a2aab0fc85 100644 --- a/commands/loadxy.c +++ b/commands/loadxy.c @@ -67,8 +67,7 @@ static int do_loady(int argc, char *argv[]) cname = optarg; break; default: - perror(argv[0]); - return 1; + return COMMAND_ERROR_USAGE; } } diff --git a/commands/ls.c b/commands/ls.c index ce02f16c49..331a4d2015 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -143,6 +143,8 @@ static int do_ls(int argc, char *argv[]) case 'l': flags &= ~LS_COLUMN; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/mem.c b/commands/mem.c index 907f1f76a8..29eaa80b23 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -74,7 +74,7 @@ int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, *swab = 1; break; default: - return -1; + return COMMAND_ERROR_USAGE; } } diff --git a/commands/menutree.c b/commands/menutree.c index ea5f65f3a1..cf37b01601 100644 --- a/commands/menutree.c +++ b/commands/menutree.c @@ -26,6 +26,8 @@ static int do_menutree(int argc, char *argv[]) case 'm': path = optarg; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/reset.c b/commands/reset.c index 830048049a..6eac532623 100644 --- a/commands/reset.c +++ b/commands/reset.c @@ -34,6 +34,8 @@ static int cmd_reset(int argc, char *argv[]) case 'f': shutdown_flag = 0; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/splash.c b/commands/splash.c index 15b296b680..2b70b29683 100644 --- a/commands/splash.c +++ b/commands/splash.c @@ -41,6 +41,8 @@ static int do_splash(int argc, char *argv[]) case 'y': s.y = simple_strtoul(optarg, NULL, 0); break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/usb.c b/commands/usb.c index 48c6619fde..9a23aa229d 100644 --- a/commands/usb.c +++ b/commands/usb.c @@ -123,6 +123,8 @@ static int do_usb(int argc, char *argv[]) case 's': show = 1; break; + default: + return COMMAND_ERROR_USAGE; } } diff --git a/commands/usbserial.c b/commands/usbserial.c index e80b315250..ad6bc63fcc 100644 --- a/commands/usbserial.c +++ b/commands/usbserial.c @@ -44,6 +44,8 @@ static int do_usbserial(int argc, char *argv[]) case 'd': usb_serial_unregister(); return 0; + default: + return COMMAND_ERROR_USAGE; } } -- cgit v1.2.3