diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-23 12:21:54 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-23 12:21:54 -0700 |
commit | 7d760fd8f4fd2fb622183106912c34845e280333 (patch) | |
tree | edec27e530e6a7d8b0e984ac82d2e820d24b2da2 | |
parent | dac5be10f3f08c78cf98a4b9d4774b46b16ace40 (diff) | |
download | emacs-7d760fd8f4fd2fb622183106912c34845e280333.tar.gz |
movemail: don't dump core if the current time is outlandish
* movemail.c (popmail): Check for mbx_delimit_begin failure.
(mbx_delimit_begin): Fail if the current time is so outlandish
that localtime would fail or asctime would have undefined
behavior. Use strftime to avoid asctime undefined behavior.
-rw-r--r-- | lib-src/ChangeLog | 8 | ||||
-rw-r--r-- | lib-src/movemail.c | 22 |
2 files changed, 19 insertions, 11 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 4ca0c7e5319..6c31841c130 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,11 @@ +2014-09-23 Paul Eggert <eggert@cs.ucla.edu> + + movemail: don't dump core if the current time is outlandish + * movemail.c (popmail): Check for mbx_delimit_begin failure. + (mbx_delimit_begin): Fail if the current time is so outlandish + that localtime would fail or asctime would have undefined + behavior. Use strftime to avoid asctime undefined behavior. + 2014-09-01 Paul Eggert <eggert@cs.ucla.edu> --enable-silent-rules now suppresses more chatter. diff --git a/lib-src/movemail.c b/lib-src/movemail.c index c600fc0ea53..b0196b309d8 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -714,8 +714,8 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse for (i = start; i * increment <= end * increment; i += increment) { - mbx_delimit_begin (mbf); - if (pop_retr (server, i, mbf) != OK) + if (mbx_delimit_begin (mbf) != OK + || pop_retr (server, i, mbf) != OK) { error ("%s", Errmsg, 0); close (mbfi); @@ -832,15 +832,15 @@ mbx_write (char *line, int len, FILE *mbf) static int mbx_delimit_begin (FILE *mbf) { - time_t now; - struct tm *ltime; - char fromline[40] = "From movemail "; - - now = time (NULL); - ltime = localtime (&now); - - strcat (fromline, asctime (ltime)); - + time_t now = time (NULL); + struct tm *ltime = localtime (&now); + if (!ltime) + return NOTOK; + + char fromline[100]; + if (! strftime (fromline, sizeof fromline, + "From movemail %a %b %e %T %Y\n", ltime)) + return NOTOK; if (fputs (fromline, mbf) == EOF) return (NOTOK); return (OK); |