diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2018-03-19 14:51:46 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2018-03-19 14:51:46 +0000 |
commit | 574dc1a20f2479f7c4496c96570c94cc8e04210a (patch) | |
tree | e86cfb8a1fe4b8894135d7cc4617d55d98b88d85 /sbin/shutdown | |
parent | afd868262ef326cab29f576a4f6f736c862731ef (diff) |
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@
Diffstat (limited to 'sbin/shutdown')
-rw-r--r-- | sbin/shutdown/shutdown.c | 15 |
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; } |