]> granicus.if.org Git - mutt/commitdiff
mutt_parse_date () shouldn't modify its argument. Problem noted by
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Jan 1999 09:35:07 +0000 (09:35 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Jan 1999 09:35:07 +0000 (09:35 +0000)
Byrial Jensen.

handler.c
parse.c
protos.h

index ede357c2fd069697fda6eef183f07eae6fd9f299..4952f95ba48ef893a8e1a4b0a02a591843f15b8f 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1231,14 +1231,8 @@ static void external_body_handler (BODY *b, STATE *s)
   }
 
   expiration = mutt_get_parameter ("expiration", b->parameter);
-  if (expiration) 
-  {
-    /* mutt_parse_date() will alter its argument, so we need a copy */
-    char *e = safe_strdup (expiration);
-
-    expire = mutt_parse_date (e, NULL);
-    free (e);
-  }
+  if (expiration)
+    expire = mutt_parse_date (expiration, NULL);
   else
     expire = -1;
 
diff --git a/parse.c b/parse.c
index ad8be3f3c5e6ee705c24789bfc1ea9bd016b515e..d3ae5c485e56142c697716617c289df6f73c22ff 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -660,7 +660,7 @@ TimeZones[] =
  * This routine assumes that `h' has been initialized to 0.  the `timezone'
  * field is optional, defaulting to +0000 if missing.
  */
-time_t mutt_parse_date (char *s, HEADER *h)
+time_t mutt_parse_date (const char *s, HEADER *h)
 {
   int count = 0;
   char *t;
@@ -673,12 +673,19 @@ time_t mutt_parse_date (char *s, HEADER *h)
   int zoccident = 0;
   const char *ptz;
   char tzstr[SHORT_STRING];
+  char scratch[SHORT_STRING];
 
+  /* Don't modify our argument. Fixed-size buffer is ok here since
+   * the date format imposes a natural limit. 
+   */
+
+  strfcpy (scratch, s, sizeof (scratch));
+  
   /* kill the day of the week, if it exists. */
-  if ((t = strchr (s, ',')))
+  if ((t = strchr (scratch, ',')))
     t++;
   else
-    t = s;
+    t = scratch;
   SKIPWS (t);
 
   memset (&tm, 0, sizeof (tm));
index 7aaf35b0f3d73116a08172707c3a59f3b3070d25..03ff480563226148d4862b1b6370779d29fee057 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -97,7 +97,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY *, int, ATTACHPTR **, short *, short *, i
 time_t mutt_local_tz (void);
 time_t mutt_mktime (struct tm *, int);
 time_t is_from (const char *, char *, size_t);
-time_t mutt_parse_date (char *, HEADER *);
+time_t mutt_parse_date (const char *, HEADER *);
 
 const char *mutt_attach_fmt (
        char *dest,