nvram: fix crash when get, set or unset is invoked without argument (#7263)
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 2 May 2010 00:45:03 +0000 (00:45 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 2 May 2010 00:45:03 +0000 (00:45 +0000)
SVN-Revision: 21288

package/nvram/Makefile
package/nvram/src/cli.c

index 6ac11a9befc3122076c2f11e2330351d2655d9be..f064b5fe3c013e8ec8d9bfe93965d3c9a775c398 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=nvram
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
index 953910cd68614341762aaaf155c70ed8de3dd1b1..44d4b88fdee69d68447d59bc85b573ff1c6f4636 100644 (file)
@@ -165,20 +165,32 @@ int main( int argc, const char *argv[] )
                                stat = do_info(nvram);
                                done++;
                        }
-                       else if( !strcmp(argv[i], "get") && ++i < argc )
+                       else if( !strcmp(argv[i], "get") || !strcmp(argv[i], "unset") || !strcmp(argv[i], "set") )
                        {
-                               stat = do_get(nvram, argv[i]);
-                               done++;
-                       }
-                       else if( !strcmp(argv[i], "unset") && ++i < argc )
-                       {
-                               stat = do_unset(nvram, argv[i]);
-                               done++;
-                       }
-                       else if( !strcmp(argv[i], "set") && ++i < argc )
-                       {
-                               stat = do_set(nvram, argv[i]);
-                               done++;
+                               if( (i+1) < argc )
+                               {
+                                       switch(argv[i++][0])
+                                       {
+                                               case 'g':
+                                                       stat = do_get(nvram, argv[i]);
+                                                       break;
+
+                                               case 'u':
+                                                       stat = do_unset(nvram, argv[i]);
+                                                       break;
+
+                                               case 's':
+                                                       stat = do_set(nvram, argv[i]);
+                                                       break;
+                                       }
+                                       done++;
+                               }
+                               else
+                               {
+                                       fprintf(stderr, "Command '%s' requires an argument!\n", argv[i]);
+                                       done = 0;
+                                       break;
+                               }
                        }
                        else if( !strcmp(argv[i], "commit") )
                        {