summaryrefslogtreecommitdiff
path: root/usr.sbin/ospfctl
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-01-25 16:27:01 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-01-25 16:27:01 +0000
commit100223db3c4f124c158b08f7ee4ed2366273bf57 (patch)
treee4f3af42ac69314a864a1994fff20399986028f0 /usr.sbin/ospfctl
parent9e9734e2e991625de0abe903a9083fb5e10c36c0 (diff)
Correctly detect missing arguments like in "ospfctl show data area".
OK henning@ norby@
Diffstat (limited to 'usr.sbin/ospfctl')
-rw-r--r--usr.sbin/ospfctl/parser.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/usr.sbin/ospfctl/parser.c b/usr.sbin/ospfctl/parser.c
index 11babc4a357..dd243a331e7 100644
--- a/usr.sbin/ospfctl/parser.c
+++ b/usr.sbin/ospfctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.11 2006/03/23 18:37:34 norby Exp $ */
+/* $OpenBSD: parser.c,v 1.12 2007/01/25 16:27:00 claudio Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -139,7 +139,7 @@ parse(int argc, char *argv[])
bzero(&res, sizeof(res));
- while (argc > 0) {
+ while (argc >= 0) {
if ((match = match_token(argv[0], table)) == NULL) {
fprintf(stderr, "valid commands/args:\n");
show_valid_args(table);
@@ -197,7 +197,7 @@ match_token(const char *word, const struct token table[])
}
break;
case ADDRESS:
- if (parse_addr(word, &res.addr)) {
+ if (word != NULL && parse_addr(word, &res.addr)) {
match++;
t = &table[i];
if (t->value)
@@ -205,7 +205,8 @@ match_token(const char *word, const struct token table[])
}
break;
case PREFIX:
- if (parse_prefix(word, &res.addr, &res.prefixlen)) {
+ if (word != NULL &&
+ parse_prefix(word, &res.addr, &res.prefixlen)) {
match++;
t = &table[i];
if (t->value)
@@ -231,9 +232,11 @@ match_token(const char *word, const struct token table[])
}
if (match != 1) {
- if (match > 1)
+ if (word == NULL)
+ fprintf(stderr, "missing argument:\n");
+ else if (match > 1)
fprintf(stderr, "ambiguous argument: %s\n", word);
- if (match < 1)
+ else if (match < 1)
fprintf(stderr, "unknown argument: %s\n", word);
return (NULL);
}