summaryrefslogtreecommitdiffstats
path: root/date.c
diff options
context:
space:
mode:
authorEike Rathke <erack@erack.de>2018-06-18 22:04:47 +0200
committerEike Rathke <erack@erack.de>2018-06-18 22:04:47 +0200
commit4bc76c2f3d425a95b30b06cc73cb7c73f34f26db (patch)
tree3beb1740ec413eb36ceab7ace6511545c26d3f47 /date.c
parent508ff2377e1394b2c3dc63602da3e81a4d0cdb52 (diff)
Allow larger passphrase timeout values
This came up in the comp.mail.mutt newsgroup where a user wasn't satisfied with the SHORT_MAX seconds ~9 hours limit on passphrase timeouts. For the first time made it necessary for the options parser to be able to parse numbers as long values. Also, introduced mutt_add_timeout() to detect possible overflow before adding a timeout to a time_t value and truncate to TIME_T_MAX instead.
Diffstat (limited to 'date.c')
-rw-r--r--date.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/date.c b/date.c
index 2a8d4b47..497ffdd4 100644
--- a/date.c
+++ b/date.c
@@ -120,6 +120,19 @@ time_t mutt_mktime (struct tm *t, int local)
return (g);
}
+/* Safely add a timeout to a given time_t value, truncating instead of
+ * overflowing. */
+time_t mutt_add_timeout (time_t now, long timeout)
+{
+ if (timeout < 0)
+ return now;
+
+ if (TIME_T_MAX - now < timeout)
+ return TIME_T_MAX;
+
+ return now + timeout;
+}
+
/* Return 1 if month is February of leap year, else 0 */
static int isLeapYearFeb (struct tm *tm)
{