diff options
author | 2007-01-29 10:28:11 +0000 | |
---|---|---|
committer | 2007-01-29 10:28:11 +0000 | |
commit | 6ee110630848d0f8e53a57f75707031e4dd25d6a (patch) | |
tree | c93ff89fc24f85b38c076396092dae40aab121df | |
parent | hey look, i found another debug printf from my merging stuff! (diff) | |
download | wireguard-openbsd-6ee110630848d0f8e53a57f75707031e4dd25d6a.tar.xz wireguard-openbsd-6ee110630848d0f8e53a57f75707031e4dd25d6a.zip |
Correctly check for missing arguments, as in ospfctl/bgpctl. OK pyr@
-rw-r--r-- | usr.sbin/hoststatectl/parser.c | 16 | ||||
-rw-r--r-- | usr.sbin/relayctl/parser.c | 16 |
2 files changed, 24 insertions, 8 deletions
diff --git a/usr.sbin/hoststatectl/parser.c b/usr.sbin/hoststatectl/parser.c index 7112c06b2de..708fee48bc0 100644 --- a/usr.sbin/hoststatectl/parser.c +++ b/usr.sbin/hoststatectl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.5 2007/01/09 00:45:32 deraadt Exp $ */ +/* $OpenBSD: parser.c,v 1.6 2007/01/29 10:28:11 claudio Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -115,7 +115,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); @@ -166,6 +166,8 @@ match_token(const char *word, const struct token table[]) } break; case HOSTID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -175,6 +177,8 @@ match_token(const char *word, const struct token table[]) match++; break; case TABLEID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -184,6 +188,8 @@ match_token(const char *word, const struct token table[]) match++; break; case SERVICEID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -198,9 +204,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); } diff --git a/usr.sbin/relayctl/parser.c b/usr.sbin/relayctl/parser.c index 7112c06b2de..708fee48bc0 100644 --- a/usr.sbin/relayctl/parser.c +++ b/usr.sbin/relayctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.5 2007/01/09 00:45:32 deraadt Exp $ */ +/* $OpenBSD: parser.c,v 1.6 2007/01/29 10:28:11 claudio Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -115,7 +115,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); @@ -166,6 +166,8 @@ match_token(const char *word, const struct token table[]) } break; case HOSTID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -175,6 +177,8 @@ match_token(const char *word, const struct token table[]) match++; break; case TABLEID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -184,6 +188,8 @@ match_token(const char *word, const struct token table[]) match++; break; case SERVICEID: + if (word == NULL) + break; res.id.id = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) { strlcpy(res.id.name, word, sizeof(res.id.name)); @@ -198,9 +204,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); } |