diff options
author | Steve Bennett <steveb@workware.net.au> | 2010-04-07 19:16:12 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-07 19:16:12 +0200 |
commit | 823b636cd14d337ebb8766c5c181737fb3860b42 (patch) | |
tree | 0b7d3e55e5e84f5f3edce42d3cb9e03cec12c763 | |
parent | 39601843d70247a4c40f3810157a331fb8a7193b (diff) | |
download | busybox-w32-823b636cd14d337ebb8766c5c181737fb3860b42.tar.gz busybox-w32-823b636cd14d337ebb8766c5c181737fb3860b42.tar.bz2 busybox-w32-823b636cd14d337ebb8766c5c181737fb3860b42.zip |
ipcalc: more correct checking for proper number of arguments
function old new delta
ipcalc_main 581 569 -12
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ipcalc.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 78558495e..17b216354 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -63,13 +63,13 @@ int get_prefix(unsigned long netmask); | |||
63 | 63 | ||
64 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS | 64 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS |
65 | static const char ipcalc_longopts[] ALIGN1 = | 65 | static const char ipcalc_longopts[] ALIGN1 = |
66 | "netmask\0" No_argument "m" | 66 | "netmask\0" No_argument "m" // netmask from IP (assuming complete class A, B, or C network) |
67 | "broadcast\0" No_argument "b" | 67 | "broadcast\0" No_argument "b" // broadcast from IP [netmask] |
68 | "network\0" No_argument "n" | 68 | "network\0" No_argument "n" // network from IP [netmask] |
69 | # if ENABLE_FEATURE_IPCALC_FANCY | 69 | # if ENABLE_FEATURE_IPCALC_FANCY |
70 | "prefix\0" No_argument "p" | 70 | "prefix\0" No_argument "p" // prefix from IP[/prefix] [netmask] |
71 | "hostname\0" No_argument "h" | 71 | "hostname\0" No_argument "h" // hostname from IP |
72 | "silent\0" No_argument "s" | 72 | "silent\0" No_argument "s" // don’t ever display error messages |
73 | # endif | 73 | # endif |
74 | ; | 74 | ; |
75 | #endif | 75 | #endif |
@@ -92,15 +92,16 @@ int ipcalc_main(int argc UNUSED_PARAM, char **argv) | |||
92 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS | 92 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS |
93 | applet_long_options = ipcalc_longopts; | 93 | applet_long_options = ipcalc_longopts; |
94 | #endif | 94 | #endif |
95 | opt_complementary = "-1:?2"; /* minimum 1 arg, maximum 2 args */ | ||
95 | opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs")); | 96 | opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs")); |
96 | argv += optind; | 97 | argv += optind; |
97 | if (opt & SILENT) | 98 | if (opt & SILENT) |
98 | logmode = LOGMODE_NONE; /* suppress error_msg() output */ | 99 | logmode = LOGMODE_NONE; /* suppress error_msg() output */ |
99 | if (opt & (BROADCAST | NETWORK | NETPREFIX)) { | 100 | opt &= ~SILENT; |
100 | if (!argv[0] || !argv[1] || argv[2]) | 101 | if (!(opt & (BROADCAST | NETWORK | NETPREFIX))) { |
101 | bb_show_usage(); | 102 | /* if no options at all or |
102 | } else { | 103 | * (no broadcast,network,prefix) and (two args)... */ |
103 | if (!argv[0] || argv[1]) | 104 | if (!opt || argv[1]) |
104 | bb_show_usage(); | 105 | bb_show_usage(); |
105 | } | 106 | } |
106 | 107 | ||