]> git.eshelyaron.com Git - emacs.git/commitdiff
movemail: don't dump core if the current time is outlandish
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 23 Sep 2014 19:21:54 +0000 (12:21 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 23 Sep 2014 19:21:54 +0000 (12:21 -0700)
* 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.

lib-src/ChangeLog
lib-src/movemail.c

index 4ca0c7e5319779214cdff8011794bb7dac125c61..6c31841c1305f1ba5054c3b5a76ef1532d2d2dce 100644 (file)
@@ -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.
index c600fc0ea536428792fdf6f24af1698193abb626..b0196b309d8b8efb2734a7783cb944f5d5873363 100644 (file)
@@ -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);