From brandt@fokus.gmd.de Fri Jan 18 03:46:56 2002 Return-Path: Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by hub.freebsd.org (Postfix) with ESMTP id CB46A37B417 for ; Fri, 18 Jan 2002 03:46:54 -0800 (PST) Received: from fokus.gmd.de (beagle [193.175.132.100]) by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id g0IBkpR07270 for ; Fri, 18 Jan 2002 12:46:52 +0100 (MET) Received: (from root@localhost) by fokus.gmd.de (8.11.6/8.11.0) id g0IBkp672380; Fri, 18 Jan 2002 12:46:51 +0100 (CET) (envelope-from hbb) Message-Id: <200201181146.g0IBkp672380@fokus.gmd.de> Date: Fri, 18 Jan 2002 12:46:51 +0100 (CET) From: Hartmut Brandt Reply-To: Hartmut Brandt To: FreeBSD-gnats-submit@freebsd.org Cc: Subject: syslog(3) clobbers static storage used by ctime(3) X-Send-Pr-Version: 3.113 X-GNATS-Notify: >Number: 34022 >Category: bin >Synopsis: syslog(3) clobbers static storage used by ctime(3) >Confidential: no >Severity: serious >Priority: high >Responsible: dwmalone >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 18 03:50:02 PST 2002 >Closed-Date: Sat Feb 16 04:25:08 PST 2002 >Last-Modified: Sat Feb 16 04:25:33 PST 2002 >Originator: Hartmut Brandt >Release: FreeBSD 5.0-CURRENT i386 >Organization: Fraunhofer FOKUS >Environment: System: FreeBSD beagle.fokus.gmd.de 5.0-CURRENT FreeBSD 5.0-CURRENT #7: Fri Jan 11 13:15:44 CET 2002 hbb@beagle.fokus.gmd.de:/opt/obj/usr/src/sys/BEAGLE i386 >Description: syslog(3) calls ctime() to put a timestamp into the line that is to be logged. ctime() in turn calls localtime() and so ctime() clobbers the static storage used for the string by itself and the static storage used by localtime() for a struct tm. >How-To-Repeat: put the line syslog(LOG_ERR, "timestamp %s", ctime(&t)); into a program using syslog(3) with a value of t that is different from the current time. Observe, that the two times printed in the log file are the same. >Fix: Apply the following fix to /usr/src/lib/libc/gen/syslog.c: Index: syslog.c =================================================================== RCS file: /usr/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.22 diff -c -r1.22 syslog.c *** syslog.c 24 Jan 2001 12:59:24 -0000 1.22 --- syslog.c 18 Jan 2002 11:18:32 -0000 *************** *** 143,149 **** register char ch, *p; time_t now; int fd, saved_errno; ! char *stdp, tbuf[2048], fmt_cpy[1024]; FILE *fp, *fmt_fp; struct bufcookie tbuf_cookie; struct bufcookie fmt_cookie; --- 143,149 ---- register char ch, *p; time_t now; int fd, saved_errno; ! char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26]; FILE *fp, *fmt_fp; struct bufcookie tbuf_cookie; struct bufcookie fmt_cookie; *************** *** 176,182 **** /* Build the message. */ (void)time(&now); (void)fprintf(fp, "<%d>", pri); ! (void)fprintf(fp, "%.15s ", ctime(&now) + 4); if (LogStat & LOG_PERROR) { /* Transfer to string buffer */ (void)fflush(fp); --- 176,182 ---- /* Build the message. */ (void)time(&now); (void)fprintf(fp, "<%d>", pri); ! (void)fprintf(fp, "%.15s ", ctime_r(&now, timbuf) + 4); if (LogStat & LOG_PERROR) { /* Transfer to string buffer */ (void)fflush(fp); >Release-Note: >Audit-Trail: Responsible-Changed-From-To: freebsd-bugs->dwmalone Responsible-Changed-By: dwmalone Responsible-Changed-When: Thu Jan 24 14:38:00 PST 2002 Responsible-Changed-Why: Patch seems sensible. I'll test and commit it. http://www.FreeBSD.org/cgi/query-pr.cgi?pr=34022 State-Changed-From-To: open->closed State-Changed-By: dwmalone State-Changed-When: Sat Feb 16 04:25:08 PST 2002 State-Changed-Why: Fixed in -current and -stable. Thanks. http://www.FreeBSD.org/cgi/query-pr.cgi?pr=34022 >Unformatted: