From f6bf9f9999370d13016218057a56c81e8192ec0d Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 17 Apr 2015 00:31:22 -0400 Subject: [PATCH] protect against bad dates A recent fault on mingw32 revealed that faulty code which passes a bad or out-of-range date value could have game-fatal consequences. Add some protection. --- src/hacklib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hacklib.c b/src/hacklib.c index cf2dbea62..4788f2d08 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -792,6 +792,7 @@ time_from_yyyymmddhhmmss(buf) char *buf; { int k; + time_t timeresult; struct tm t, *lt; char *g, *p, y[5],mo[3],md[3],h[3],mi[3],s[3]; if (buf && strlen(buf) == 14) { @@ -829,8 +830,13 @@ char *buf; t.tm_hour = atoi(h); t.tm_min = atoi(mi); t.tm_sec = atoi(s); - return mktime(&t); + timeresult = mktime(&t); } + if ((int)timeresult == -1) + debugpline1("time_from_yyyymmddhhmmss(%s) would have returned -1", + buf ? buf : ""); + else + return timeresult; } return (time_t)0; }