aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/nvram
diff options
context:
space:
mode:
authorBangLang Huang <banglang.huang@foxmail.com>2017-02-24 10:52:52 +0800
committerJo-Philipp Wich <jo@mein.io>2017-12-13 16:23:39 +0100
commit118a2ea0bcdfb3895dfdec9fe4b98be5325d6386 (patch)
treeed5657d0d73c5c45583aec7bbad440cdb3dc6bf9 /package/utils/nvram
parentc446ee4ad42731ef99cbefee7dcc2bcab1c26566 (diff)
downloadupstream-118a2ea0bcdfb3895dfdec9fe4b98be5325d6386.tar.gz
upstream-118a2ea0bcdfb3895dfdec9fe4b98be5325d6386.tar.bz2
upstream-118a2ea0bcdfb3895dfdec9fe4b98be5325d6386.zip
nvram: improve argument check when program start
print help message when argument count is less than 2. Signed-off-by: BangLang Huang <banglang.huang@foxmail.com> (cherry picked from commit c7e2a6fe923dc86bab14d94ead322a045efca4c9)
Diffstat (limited to 'package/utils/nvram')
-rw-r--r--package/utils/nvram/src/cli.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/package/utils/nvram/src/cli.c b/package/utils/nvram/src/cli.c
index 149d307474..538bdce648 100644
--- a/package/utils/nvram/src/cli.c
+++ b/package/utils/nvram/src/cli.c
@@ -155,15 +155,16 @@ int main( int argc, const char *argv[] )
int done = 0;
int i;
+ if( argc < 2 ) {
+ usage();
+ return 1;
+ }
+
/* Ugly... iterate over arguments to see whether we can expect a write */
- for( i = 1; i < argc; i++ )
- if( ( !strcmp(argv[i], "set") && ++i < argc ) ||
- ( !strcmp(argv[i], "unset") && ++i < argc ) ||
- !strcmp(argv[i], "commit") )
- {
- write = 1;
- break;
- }
+ if( ( !strcmp(argv[1], "set") && 2 < argc ) ||
+ ( !strcmp(argv[1], "unset") && 2 < argc ) ||
+ !strcmp(argv[1], "commit") )
+ write = 1;
nvram = write ? nvram_open_staging() : nvram_open_rdonly();