From: Ben Harris Date: Sat, 24 Nov 2018 10:34:31 +0000 (+0000) Subject: Slightly more robust state string parsing. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=780ee826599810774b6dab912a6b44808a6206fb;p=clunk.git Slightly more robust state string parsing. --- diff --git a/clunk.c b/clunk.c index b2ce67c..853299d 100644 --- a/clunk.c +++ b/clunk.c @@ -158,9 +158,15 @@ pulse() static void init_statestring(char const *str) { + if (sscanf(str, "%d:%d:%d", &displayed.tm_hour, &displayed.tm_min, &displayed.tm_sec) != 3) - errx(1, "usage"); + errx(1, "Bad state string '%s'", str); + if (displayed.tm_hour < 0 || displayed.tm_hour > 23 || + displayed.tm_min < 0 || displayed.tm_min > 59 || + displayed.tm_sec < 0 || displayed.tm_sec > 59) + errx(1, "Bad state string '%s'", str); + displayed.tm_hour %= 12; } static void @@ -176,6 +182,7 @@ init_statefile(char const *statefilename) if (len == -1) err(1, "read %s", statefilename); if (len > 0) { + while (len > 0 && buf[len - 1] == '\n') len--; buf[len] = '\0'; init_statestring(buf); }