]> granicus.if.org Git - mutt/commitdiff
Allow larger passphrase timeout values
authorEike Rathke <erack@erack.de>
Mon, 18 Jun 2018 20:04:47 +0000 (22:04 +0200)
committerEike Rathke <erack@erack.de>
Mon, 18 Jun 2018 20:04:47 +0000 (22:04 +0200)
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.

date.c
doc/makedoc.c
doc/manual.xml.head
globals.h
init.c
init.h
pgp.c
protos.h
smime.c

diff --git a/date.c b/date.c
index 2a8d4b470c07100e1a7489031293e4a6d35d1f49..497ffdd429e61a3a011cc7a6b97cd742f2fa65ff 100644 (file)
--- 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)
 {
index 8b12d7f72d63c960ad5b0b04893846071d4fb1ff..a84554b7604cafb9776d45c021d5f28f0b92a011 100644 (file)
@@ -351,6 +351,7 @@ enum
   DT_NONE = 0,
   DT_BOOL,
   DT_NUM,
+  DT_LNUM,
   DT_STR,
   DT_PATH,
   DT_QUAD,
@@ -372,6 +373,7 @@ types[] =
   { "DT_NONE", "-none-"        },
   { "DT_BOOL",  "boolean"      },
   { "DT_NUM",   "number"       },
+  { "DT_LNUM",  "number (long)"        },
   { "DT_STR",  "string"        },
   { "DT_PATH", "path"          },
   { "DT_QUAD", "quadoption"    },
index 2f4bc5cc892bff416bfd662e493daafda24c4ad5..8ac8fd9dcca2f97bce67186efa008d076721320d 100644 (file)
@@ -4144,6 +4144,14 @@ A signed integer number in the range -32768 to 32767.
 </listitem>
 </varlistentry>
 <varlistentry>
+<term>number (long)</term>
+<listitem>
+<para>
+A signed integer number in the range -2147483648 to 2147483647.
+</para>
+</listitem>
+</varlistentry>
+<varlistentry>
 <term>string</term>
 <listitem>
 <para>
index 2aa96f908f2bcb11d9d4d3dc126a93f774717c69..116ba60b0a5c38291d539a06f6efb149b9cc2319 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -254,7 +254,7 @@ WHERE REGEXP PgpGoodSign;
 WHERE REGEXP PgpDecryptionOkay;
 WHERE char *PgpDefaultKey;
 WHERE char *PgpSignAs;
-WHERE short PgpTimeout;
+WHERE long  PgpTimeout;
 WHERE char *PgpEntryFormat;
 WHERE char *PgpClearSignCommand;
 WHERE char *PgpDecodeCommand;
@@ -273,7 +273,7 @@ WHERE char *PgpGetkeysCommand;
 /*-- formerly in smime.h --*/
 WHERE char *SmimeDefaultKey;
 WHERE char *SmimeSignAs;
-WHERE short SmimeTimeout;
+WHERE long  SmimeTimeout;
 WHERE char *SmimeCertificates;
 WHERE char *SmimeKeys;
 WHERE char *SmimeCryptAlg;
diff --git a/init.c b/init.c
index 2e010674e67c349c6a9bb11b1ddb2556add1c142..60808003d4cdfc79bfefb596f08f08fefdb1eee6 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1766,6 +1766,9 @@ static void mutt_restore_default (struct option_t *p)
     case DT_MAGIC:
       *((short *) p->data) = p->init;
       break;
+    case DT_LNUM:
+      *((long *) p->data) = p->init;
+      break;
     case DT_RX:
       {
        REGEXP *pp = (REGEXP *) p->data;
@@ -2492,6 +2495,38 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
           *ptr = 0;
       }
 #endif
+    }
+    else if (DTYPE(MuttVars[idx].type) == DT_LNUM)
+    {
+      long *ptr = (long *) MuttVars[idx].data;
+      long val;
+      int rc;
+
+      if (query || *s->dptr != '=')
+      {
+       val = *ptr;
+
+       /* user requested the value of this variable */
+       snprintf (err->data, err->dsize, "%s=%ld", MuttVars[idx].option, val);
+       break;
+      }
+
+      CHECK_PAGER;
+      s->dptr++;
+
+      mutt_extract_token (tmp, s, 0);
+      rc = mutt_atol (tmp->data, (long *) &val);
+
+      if (rc < 0 || !*tmp->data)
+      {
+       snprintf (err->data, err->dsize, _("%s: invalid value (%s)"), tmp->data,
+                 rc == -1 ? _("format error") : _("number overflow"));
+       r = -1;
+       break;
+      }
+      else
+       *ptr = val;
+
     }
     else if (DTYPE (MuttVars[idx].type) == DT_QUAD)
     {
@@ -3065,6 +3100,12 @@ static int var_to_string (int idx, char* val, size_t len)
 
     snprintf (tmp, sizeof (tmp), "%d", sval);
   }
+  else if (DTYPE (MuttVars[idx].type) == DT_LNUM)
+  {
+    long sval = *((long *) MuttVars[idx].data);
+
+    snprintf (tmp, sizeof (tmp), "%ld", sval);
+  }
   else if (DTYPE (MuttVars[idx].type) == DT_SORT)
   {
     const struct mapping_t *map;
diff --git a/init.h b/init.h
index 983fde4bfcbefb6045f2ab944ebd729f8f7b2e09..9858a50cc618771d63f81ae48cc91386c3354701 100644 (file)
--- a/init.h
+++ b/init.h
@@ -29,7 +29,7 @@
 #ifndef _MAKEDOC
 #define DT_MASK                0x0f
 #define DT_BOOL                1 /* boolean option */
-#define DT_NUM         2 /* a number */
+#define DT_NUM         2 /* a number (short) */
 #define DT_STR         3 /* a string */
 #define DT_PATH                4 /* a pathname */
 #define DT_QUAD                5 /* quad-option (yes/no/ask-yes/ask-no) */
@@ -39,6 +39,7 @@
 #define DT_SYN         9 /* synonym for another variable */
 #define DT_ADDR               10 /* e-mail address */
 #define DT_MBCHARTBL   11 /* multibyte char table */
+#define DT_LNUM        12 /* a number (long) */
 
 #define DTYPE(x) ((x) & DT_MASK)
 
@@ -2265,7 +2266,7 @@ struct option_t MuttVars[] = {
   ** this if you know what you are doing.
   ** (PGP only)
   */
-  { "pgp_timeout",     DT_NUM,  R_NONE, UL &PgpTimeout, 300 },
+  { "pgp_timeout",     DT_LNUM,         R_NONE, UL &PgpTimeout, 300 },
   /*
   ** .pp
   ** The number of seconds after which a cached passphrase will expire if
@@ -3306,7 +3307,7 @@ struct option_t MuttVars[] = {
   ** possible \fCprintf(3)\fP-like sequences.
   ** (S/MIME only)
   */
-  { "smime_timeout",           DT_NUM,  R_NONE, UL &SmimeTimeout, 300 },
+  { "smime_timeout",           DT_LNUM,         R_NONE, UL &SmimeTimeout, 300 },
   /*
   ** .pp
   ** The number of seconds after which a cached passphrase will expire if
diff --git a/pgp.c b/pgp.c
index 60971119eb9ca7f37b7c384686928f7a5e73bc92..776af84ed39d0d1ca53db628a34e8131e1b55e8c 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -90,7 +90,7 @@ int pgp_valid_passphrase (void)
 
   if (mutt_get_password (_("Enter PGP passphrase:"), PgpPass, sizeof (PgpPass)) == 0)
     {
-      PgpExptime = time (NULL) + PgpTimeout;
+      PgpExptime = mutt_add_timeout (time (NULL), PgpTimeout);
       return (1);
     }
   else
index 4076d861b6e6da5a7f59940c0494cd68127c9c51..432304e57d2e07bd2d3b299dfec914feeb3445b7 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -121,6 +121,7 @@ time_t mutt_decrease_mtime (const char *, struct stat *);
 time_t mutt_local_tz (time_t);
 time_t mutt_mktime (struct tm *, int);
 time_t mutt_parse_date (const char *, HEADER *);
+time_t mutt_add_timeout (time_t, long);
 int is_from (const char *, char *, size_t, time_t *);
 void mutt_touch_atime (int);
 int mutt_timespec_compare (struct timespec *a, struct timespec *b);
diff --git a/smime.c b/smime.c
index 823fc73de097f50a9e271327fa27acb180dc34bd..13a3e2ccec3e66fb8d2c581baa422ae5771bcd3e 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -140,7 +140,7 @@ int smime_valid_passphrase (void)
   
   if (mutt_get_password (_("Enter S/MIME passphrase:"), SmimePass, sizeof (SmimePass)) == 0)
     {
-      SmimeExptime = time (NULL) + SmimeTimeout;
+      SmimeExptime = mutt_add_timeout (time (NULL), SmimeTimeout);
       return (1);
     }
   else