summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2018-03-19 14:51:45 +0000
committercheloha <cheloha@openbsd.org>2018-03-19 14:51:45 +0000
commit44680ff5ad48b4c8f46d19d94ffb444febcaf341 (patch)
treefd36244fa2c447e4c83b6c86bb4dcaec461a9756
parentAdd regress test ensuring autoinit stays pledge("stdio") safe. (diff)
downloadwireguard-openbsd-44680ff5ad48b4c8f46d19d94ffb444febcaf341.tar.xz
wireguard-openbsd-44680ff5ad48b4c8f46d19d94ffb444febcaf341.zip
Disallow "++minutes".
strtonum(3) accepts a single leading '+', so if we increment timearg we allow input with two leading pluses. If we don't increment, we still have a valid input for strtonum(3). While here, use errstr to say what was wrong with timearg. Don't increase the range for offsets yet: it exposes segfaults elsewhere in the program that need to be addressed. ok millert@ tb@
-rw-r--r--sbin/shutdown/shutdown.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index a11f73ae862..2d6636182e6 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shutdown.c,v 1.49 2018/03/02 02:30:15 cheloha Exp $ */
+/* $OpenBSD: shutdown.c,v 1.50 2018/03/19 14:51:45 cheloha Exp $ */
/* $NetBSD: shutdown.c,v 1.9 1995/03/18 15:01:09 cgd Exp $ */
/*
@@ -464,9 +464,10 @@ die_you_gravy_sucking_pig_dog(void)
void
getoffset(char *timearg)
{
+ const char *errstr;
struct tm *lt;
int this_year;
- time_t now;
+ time_t minutes, now;
char *p;
if (!strcasecmp(timearg, "now")) { /* now */
@@ -475,13 +476,11 @@ getoffset(char *timearg)
}
(void)time(&now);
- if (*timearg == '+') { /* +minutes */
- const char *errstr;
-
- offset = strtonum(++timearg, 0, INT_MAX, &errstr);
+ if (timearg[0] == '+') { /* +minutes */
+ minutes = strtonum(timearg, 0, INT_MAX, &errstr);
if (errstr)
- badtime();
- offset *= 60;
+ errx(1, "relative offset is %s: %s", errstr, timearg);
+ offset = minutes * 60;
shuttime = now + offset;
return;
}