summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2011-03-11 17:11:15 +0000
committerderaadt <deraadt@openbsd.org>2011-03-11 17:11:15 +0000
commita6a04eb31bc6b8f4c53a239114a19150c41855ef (patch)
tree0ad568039c7de511a1827d189eccf180d84b8978
parentUse _MACHINE_ENDIAN_H_ for this is The Right Thing To Do. (diff)
downloadwireguard-openbsd-a6a04eb31bc6b8f4c53a239114a19150c41855ef.tar.xz
wireguard-openbsd-a6a04eb31bc6b8f4c53a239114a19150c41855ef.zip
Check that date(1) is not passed any extra arguments.
ok millert
-rw-r--r--bin/date/date.c15
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);