summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ospfctl
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2007-01-25 16:27:00 +0000
committerclaudio <claudio@openbsd.org>2007-01-25 16:27:00 +0000
commit532600dcfd8a402d600fb8bb150a64188862d7b9 (patch)
tree8e5b11379143de9491b898835b316c031e3e936e /usr.sbin/ospfctl
parenttypo in error message. (diff)
downloadwireguard-openbsd-532600dcfd8a402d600fb8bb150a64188862d7b9.tar.xz
wireguard-openbsd-532600dcfd8a402d600fb8bb150a64188862d7b9.zip
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);
}