diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2011-03-11 17:11:16 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2011-03-11 17:11:16 +0000 |
commit | e12dfdeade939ad75b101eac85b11cf4ca81892f (patch) | |
tree | 0ca0ab10e4121280718c0188cbbb903ff0d9d4f1 /bin/date/date.c | |
parent | ceacd60e5da242add0e76c67bad05065cbc8b952 (diff) |
Check that date(1) is not passed any extra arguments.
ok millert
Diffstat (limited to 'bin/date/date.c')
-rw-r--r-- | bin/date/date.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index 1f6ce05872b..022ef1c59cc 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -1,4 +1,4 @@ -/* $OpenBSD: date.c,v 1.33 2010/03/31 17:51:21 deraadt Exp $ */ +/* $OpenBSD: date.c,v 1.34 2011/03/11 17:11:15 deraadt Exp $ */ /* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */ /* @@ -120,16 +120,23 @@ main(int argc, char *argv[]) /* allow the operands in any order */ if (*argv && **argv == '+') { format = *argv + 1; - ++argv; + argv++; + argc--; } if (*argv) { setthetime(*argv); - ++argv; + argv++; + argc--; } - if (*argv && **argv == '+') + if (*argv && **argv == '+') { format = *argv + 1; + argc--; + } + + if (argc > 0) + errx(1, "too many arguments"); (void)strftime(buf, sizeof(buf), format, localtime(&tval)); (void)printf("%s\n", buf); |