diff options
| author | Paul Eggert | 2014-09-23 12:21:54 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-09-23 12:21:54 -0700 |
| commit | 7d760fd8f4fd2fb622183106912c34845e280333 (patch) | |
| tree | edec27e530e6a7d8b0e984ac82d2e820d24b2da2 /lib-src/movemail.c | |
| parent | dac5be10f3f08c78cf98a4b9d4774b46b16ace40 (diff) | |
| download | emacs-7d760fd8f4fd2fb622183106912c34845e280333.tar.gz emacs-7d760fd8f4fd2fb622183106912c34845e280333.zip | |
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.
Diffstat (limited to 'lib-src/movemail.c')
| -rw-r--r-- | lib-src/movemail.c | 22 |
1 files changed, 11 insertions, 11 deletions
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 | |||
| 714 | 714 | ||
| 715 | for (i = start; i * increment <= end * increment; i += increment) | 715 | for (i = start; i * increment <= end * increment; i += increment) |
| 716 | { | 716 | { |
| 717 | mbx_delimit_begin (mbf); | 717 | if (mbx_delimit_begin (mbf) != OK |
| 718 | if (pop_retr (server, i, mbf) != OK) | 718 | || pop_retr (server, i, mbf) != OK) |
| 719 | { | 719 | { |
| 720 | error ("%s", Errmsg, 0); | 720 | error ("%s", Errmsg, 0); |
| 721 | close (mbfi); | 721 | close (mbfi); |
| @@ -832,15 +832,15 @@ mbx_write (char *line, int len, FILE *mbf) | |||
| 832 | static int | 832 | static int |
| 833 | mbx_delimit_begin (FILE *mbf) | 833 | mbx_delimit_begin (FILE *mbf) |
| 834 | { | 834 | { |
| 835 | time_t now; | 835 | time_t now = time (NULL); |
| 836 | struct tm *ltime; | 836 | struct tm *ltime = localtime (&now); |
| 837 | char fromline[40] = "From movemail "; | 837 | if (!ltime) |
| 838 | 838 | return NOTOK; | |
| 839 | now = time (NULL); | 839 | |
| 840 | ltime = localtime (&now); | 840 | char fromline[100]; |
| 841 | 841 | if (! strftime (fromline, sizeof fromline, | |
| 842 | strcat (fromline, asctime (ltime)); | 842 | "From movemail %a %b %e %T %Y\n", ltime)) |
| 843 | 843 | return NOTOK; | |
| 844 | if (fputs (fromline, mbf) == EOF) | 844 | if (fputs (fromline, mbf) == EOF) |
| 845 | return (NOTOK); | 845 | return (NOTOK); |
| 846 | return (OK); | 846 | return (OK); |