diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 21 | ||||
| -rw-r--r-- | src/editfns.c | 11 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index ccc1f3923c4..15267b42d45 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,22 +1,11 @@ | |||
| 1 | 2006-03-24 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2006-03-24 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * editfns.c: Do not use ctime, since it has undefined behavior | 3 | * editfns.c (TM_YEAR_BASE): Move up, so the changes below can use it. |
| 4 | with out-of-range time stamps. This fixes a bug where | ||
| 5 | (current-time-string '(2814749767106 0)) would make Emacs dump | ||
| 6 | core on 64-bit Solaris 8. The fix is to use localtime+asctime | ||
| 7 | (checking for in-range results) instead of ctime. Please see | ||
| 8 | <http://www.opengroup.org/austin/mailarchives/ag/msg09294.html> | ||
| 9 | for more details about this portability problem. | ||
| 10 | (TM_YEAR_BASE): Move up, so the changes below can use it. | ||
| 11 | (Fdecode_time, Fencode_time): Use TM_YEAR_BASE instead of 1900. | 4 | (Fdecode_time, Fencode_time): Use TM_YEAR_BASE instead of 1900. |
| 12 | (Fdecode_time): Cast tm_year to EMACS_INT, to avoid overflow when | 5 | (Fdecode_time): Cast tm_year to EMACS_INT. |
| 13 | int is narrower than EMACS_INT. | 6 | (Fcurrent_time_string): Report an invalid time specification if |
| 14 | (Fcurrent_time_string): As with Fformat_time_string, report an | 7 | the argument is invalid. Also, check for out-of-range time |
| 15 | invalid time specification if the argument is invalid. Also, | 8 | stamps. |
| 16 | check for out-of-range time stamps; this prevents a buffer overrun | ||
| 17 | that causes Emacs to dump core on 64-bit Solaris sparc, and it | ||
| 18 | preserves the historic behavior of always returning a fixed-size | ||
| 19 | string. | ||
| 20 | 9 | ||
| 21 | 2006-03-24 Kim F. Storm <storm@cua.dk> | 10 | 2006-03-24 Kim F. Storm <storm@cua.dk> |
| 22 | 11 | ||
diff --git a/src/editfns.c b/src/editfns.c index c4f8b95d810..888bbe3062b 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1724,6 +1724,8 @@ DOW and ZONE.) */) | |||
| 1724 | XSETFASTINT (list_args[2], decoded_time->tm_hour); | 1724 | XSETFASTINT (list_args[2], decoded_time->tm_hour); |
| 1725 | XSETFASTINT (list_args[3], decoded_time->tm_mday); | 1725 | XSETFASTINT (list_args[3], decoded_time->tm_mday); |
| 1726 | XSETFASTINT (list_args[4], decoded_time->tm_mon + 1); | 1726 | XSETFASTINT (list_args[4], decoded_time->tm_mon + 1); |
| 1727 | /* On 64-bit machines an int is narrower than EMACS_INT, thus the | ||
| 1728 | cast below avoids overflow in int arithmetics. */ | ||
| 1727 | XSETINT (list_args[5], TM_YEAR_BASE + (EMACS_INT) decoded_time->tm_year); | 1729 | XSETINT (list_args[5], TM_YEAR_BASE + (EMACS_INT) decoded_time->tm_year); |
| 1728 | XSETFASTINT (list_args[6], decoded_time->tm_wday); | 1730 | XSETFASTINT (list_args[6], decoded_time->tm_wday); |
| 1729 | list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil; | 1731 | list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil; |
| @@ -1851,7 +1853,16 @@ but this is considered obsolete. */) | |||
| 1851 | 1853 | ||
| 1852 | if (! lisp_time_argument (specified_time, &value, NULL)) | 1854 | if (! lisp_time_argument (specified_time, &value, NULL)) |
| 1853 | error ("Invalid time specification"); | 1855 | error ("Invalid time specification"); |
| 1856 | /* Do not use ctime, since it has undefined behavior with | ||
| 1857 | out-of-range time stamps. This avoids a core dump triggered by | ||
| 1858 | (current-time-string '(2814749767106 0)) on 64-bit Solaris 8. See | ||
| 1859 | <http://www.opengroup.org/austin/mailarchives/ag/msg09294.html> | ||
| 1860 | for more details about this portability problem. */ | ||
| 1854 | tm = localtime (&value); | 1861 | tm = localtime (&value); |
| 1862 | /* Checking for out-of-range time stamps avoids buffer overruns that | ||
| 1863 | cause core dump on some systems (e.g., 64-bit Solaris), and also | ||
| 1864 | preserves the historic behavior of always returning a fixed-size | ||
| 1865 | 24-character string. */ | ||
| 1855 | if (! (tm && -999 - TM_YEAR_BASE <= tm->tm_year | 1866 | if (! (tm && -999 - TM_YEAR_BASE <= tm->tm_year |
| 1856 | && tm->tm_year <= 9999 - TM_YEAR_BASE)) | 1867 | && tm->tm_year <= 9999 - TM_YEAR_BASE)) |
| 1857 | error ("Specified time is not representable"); | 1868 | error ("Specified time is not representable"); |