From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: Re: Emacs current-time-string core dump on 64-bit hosts Date: Fri, 24 Mar 2006 13:09:35 -0800 Message-ID: <877j6j1re8.fsf@penguin.cs.ucla.edu> References: <87k6arnqsx.fsf@penguin.cs.ucla.edu> <87fyle6luu.fsf@penguin.cs.ucla.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1143271664 15583 80.91.229.2 (25 Mar 2006 07:27:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 25 Mar 2006 07:27:44 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 25 08:27:43 2006 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FN3BV-0006Q5-Qw for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Mar 2006 08:27:42 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FN3BU-0003rs-NY for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Mar 2006 02:27:40 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FMtXQ-0002Sd-BB for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2006 16:09:40 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FMtXP-0002SN-Bb for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2006 16:09:39 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FMtXP-0002SK-6d for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2006 16:09:39 -0500 Original-Received: from [131.179.128.19] (helo=kiwi.cs.ucla.edu) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FMtYG-0004K9-HZ; Fri, 24 Mar 2006 16:10:32 -0500 Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by kiwi.cs.ucla.edu (8.11.7p1+Sun/8.11.7/UCLACS-5.2) with ESMTP id k2OL9Z815364; Fri, 24 Mar 2006 13:09:35 -0800 (PST) Original-Received: from eggert by penguin.cs.ucla.edu with local (Exim 4.50) id 1FMtXL-0004jY-IP; Fri, 24 Mar 2006 13:09:35 -0800 Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Mon, 20 Mar 2006 20:00:50 -0500") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-Mailman-Approved-At: Sat, 25 Mar 2006 02:27:33 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:14984 Archived-At: Richard Stallman 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 * 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 (<oday); data.size = 200; data.buffer = xnew (200, char); --- 132,141 ---- labels_saved = printing = header = FALSE; ltoday = time (0); ! tm = localtime (<oday); ! 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';