Skip to content

Commit

Permalink
Fixed time parsing in shutdown when there is a + in front of a 0 time…
Browse files Browse the repository at this point in the history
… offset.

Commands with a postiive time offset (+1) would work but +0 fails.
This has been corrected by Arkadiusz Miskiewicz.
  • Loading branch information
Jesse Smith committed Aug 15, 2020
1 parent 7ca2d24 commit 462a92c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,16 +777,18 @@ int main(int argc, char **argv)
if (!strcmp(when, "now")) strcpy(when, "0");

sp = when;
if (when[0] == '+') sp++;
/* Decode shutdown time. */
/* Validate time argument. */
for ( ; *sp; sp++) {
if (*sp != ':' && (*sp < '0' || *sp > '9'))
if (*sp != '+' && *sp != ':' && (*sp < '0' || *sp > '9'))
usage();
}
sp = when;
/* Decode shutdown time. */
if (when[0] == '+') sp++;
if (strchr(when, ':') == NULL) {
/* Time in minutes. */
wt = atoi(when);
if (wt == 0 && when[0] != '0') usage();
wt = atoi(sp);
if (wt == 0 && sp[0] != '0') usage();
} else {
if (sscanf(when, "%d:%2d", &hours, &mins) != 2) usage();
/* Time in hh:mm format. */
Expand Down

0 comments on commit 462a92c

Please sign in to comment.