libbb: tidy argument checks in getopt32()
When getopt32() has complementary options it's possible to specify the minimum and maximum number of arguments allowed. Checking these values was inconsistent: - '?' correctly checked that it was followed by a digit but set the otherwise unused spec_flgs variable on error. - '=' failed to check that it was followed by a digit. function old new delta vgetopt32 1307 1319 +12 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e6f3a3b381
commit
175b8dda19
1 changed files with 5 additions and 8 deletions
|
@ -348,9 +348,6 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||||
unsigned trigger;
|
unsigned trigger;
|
||||||
int min_arg = 0;
|
int min_arg = 0;
|
||||||
int max_arg = -1;
|
int max_arg = -1;
|
||||||
int spec_flgs = 0;
|
|
||||||
|
|
||||||
#define SHOW_USAGE_IF_ERROR 1
|
|
||||||
|
|
||||||
on_off = complementary;
|
on_off = complementary;
|
||||||
memset(on_off, 0, sizeof(complementary));
|
memset(on_off, 0, sizeof(complementary));
|
||||||
|
@ -449,9 +446,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||||
continue;
|
continue;
|
||||||
c = s[1];
|
c = s[1];
|
||||||
if (*s == '?') {
|
if (*s == '?') {
|
||||||
if (c < '0' || c > '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
spec_flgs |= SHOW_USAGE_IF_ERROR;
|
|
||||||
} else {
|
|
||||||
max_arg = c - '0';
|
max_arg = c - '0';
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
@ -465,8 +460,10 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*s == '=') {
|
if (*s == '=') {
|
||||||
min_arg = max_arg = c - '0';
|
if (c >= '0' && c <= '9') {
|
||||||
s++;
|
min_arg = max_arg = c - '0';
|
||||||
|
s++;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (on_off = complementary; on_off->opt_char; on_off++)
|
for (on_off = complementary; on_off->opt_char; on_off++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue