bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs current-time-string core dump on 64-bit hosts


From: Paul Eggert
Subject: Re: Emacs current-time-string core dump on 64-bit hosts
Date: Fri, 24 Mar 2006 13:09:35 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Richard Stallman <address@hidden> writes:

> The programs in lib-src can call `ctime' safely because their
> argument is the current time.

But the current time might be out of ctime's range for many reasons:

  * a hardware problem (the hardware clock jumped far in the future or past)
  * a software problem (a bug in the 'date' program's date parser, say)
  * a human error (someone set the date incorrectly).

All three of these things have happened to me.  Admittedly I deal with
time stamps a lot, but I expect similar problems do occur to others.

How about these changes to the lib-src programs instead?  They use
asctime instead of ctime, so the changes are trivial (four lines of
code each).

2006-03-24  Paul Eggert  <address@hidden>

        * b2m.c (main): Use localtime and asctime instead of ctime,
        and sanity-check localtime's results; this avoids a buffer
        overrun and/or dereferenced null pointer if the current time
        is out of range.
        * fakemail.c (make_file_preface): Likewise.

*** lib-src/b2m.c       7 May 2004 15:26:21 -0000       1.30
--- lib-src/b2m.c       24 Mar 2006 21:03:55 -0000
*************** main (argc, argv)
*** 87,92 ****
--- 87,93 ----
  {
    logical labels_saved, printing, header;
    time_t ltoday;
+   struct tm *tm;
    char *labels, *p, *today;
    struct linebuffer data;
  
*************** main (argc, argv)
*** 131,137 ****
  
    labels_saved = printing = header = FALSE;
    ltoday = time (0);
!   today = ctime (&ltoday);
    data.size = 200;
    data.buffer = xnew (200, char);
  
--- 132,141 ----
  
    labels_saved = printing = header = FALSE;
    ltoday = time (0);
!   tm = localtime (&ltoday);
!   if (! (tm && -999 - 1900 <= tm->tm_year && tm->tm_year <= 9999 - 1900))
!     fatal ("current time is out of range");
!   today = asctime (tm);
    data.size = 200;
    data.buffer = xnew (200, char);
  
*** lib-src/fakemail.c  6 Feb 2006 11:28:28 -0000       1.35
--- lib-src/fakemail.c  24 Mar 2006 21:03:55 -0000
*************** make_file_preface ()
*** 354,359 ****
--- 354,360 ----
  {
    char *the_string, *temp;
    long idiotic_interface;
+   struct tm *tm;
    long prefix_length;
    long user_length;
    long date_length;
*************** make_file_preface ()
*** 361,367 ****
  
    prefix_length = strlen (FROM_PREFIX);
    time (&idiotic_interface);
!   the_date = ctime (&idiotic_interface);
    /* the_date has an unwanted newline at the end */
    date_length = strlen (the_date) - 1;
    the_date[date_length] = '\0';
--- 362,371 ----
  
    prefix_length = strlen (FROM_PREFIX);
    time (&idiotic_interface);
!   tm = localtime (&idiotic_interface);
!   if (! (tm && -999 - 1900 <= tm->tm_year && tm->tm_year <= 9999 - 1900))
!     fatal ("current time is out of range", 0);
!   the_date = asctime (tm);
    /* the_date has an unwanted newline at the end */
    date_length = strlen (the_date) - 1;
    the_date[date_length] = '\0';




reply via email to

[Prev in Thread] Current Thread [Next in Thread]