From: Thomas Roessler Date: Sat, 2 Jan 1999 09:35:07 +0000 (+0000) Subject: mutt_parse_date () shouldn't modify its argument. Problem noted by X-Git-Tag: archive/mutt-0-95-exp~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f959bee0d2b488f80c1f14e6940435466f52830e;p=mutt mutt_parse_date () shouldn't modify its argument. Problem noted by Byrial Jensen. --- diff --git a/handler.c b/handler.c index ede357c2..4952f95b 100644 --- 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 ad8be3f3..d3ae5c48 100644 --- 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)); diff --git a/protos.h b/protos.h index 7aaf35b0..03ff4805 100644 --- 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,