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: Sat, 25 Mar 2006 23:31:33 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Richard Stallman <address@hidden> writes:

> It seems unlikely to me that these things will be able to set the
> system's time to a value the system can't handle.  More likely the
> time will get truncated into the range the system can handle.

But I was able to temporarily set the time on a 64-bit Solaris 9 sparc
host (an UltraAX-i2 -- a several-year-old unit) to a date in the year
10001, using 64-bit GNU 'date' atop Solaris libc:

   # date -s '10001-01-01 00:00:00'; date
   Mon Jan  1 00:00:00 PST 10001
   Mon Jan  1 00:00:00 PST 10001

So there's at least one example of a host where the current time of
day can crash the 'ctime' implementation.  Admittedly, within a few
seconds the date automatically changed (to something that presumably
the time-of-day clock could represent):

   # sleep 2; date
   Sun Nov  2 00:00:01 PST 2064

However, I wouldn't be surprised if other hosts kept ticking right
along in the year 10001, even if it makes their 'ctime' crash.  The
kernel's time-of-day interface typically doesn't rely on ctime, so the
kernel's limits are unlikely to be the same as ctime's.

> Meanwhile, the system will probably crash due to demons that use ctime.

No daemons crashed in the above exercise.  I think few daemons use
ctime nowadays.  Even if some do, the overall system will probably
remain usable.

How about the following patch instead?  This one is like the earlier
one I proposed, but the code includes some comments about this stuff.

2006-03-25  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       26 Mar 2006 07:22:14 -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,143 ----
  
    labels_saved = printing = header = FALSE;
    ltoday = time (0);
!   tm = localtime (&ltoday);
!   /* Check for out-of-range dates.  Don't use 'ctime', as that might
!      dump core if the hardware clock is set to a bizarre value.  */
!   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  26 Mar 2006 07:22:14 -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,373 ----
  
    prefix_length = strlen (FROM_PREFIX);
    time (&idiotic_interface);
!   tm = localtime (&idiotic_interface);
!   /* Check for out-of-range dates.  Don't use 'ctime', as that might
!      dump core if the hardware clock is set to a bizarre value.  */
!   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]