From owner-freebsd-bugs Fri Jan 18 3:50:22 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 2DFD337B423 for ; Fri, 18 Jan 2002 03:50:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g0IBo2257200; Fri, 18 Jan 2002 03:50:02 -0800 (PST) (envelope-from gnats) 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 X-Send-Pr-Version: 3.113 Subject: bin/34022: syslog(3) clobbers static storage used by ctime(3) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 34022 >Category: bin >Synopsis: syslog(3) clobbers static storage used by ctime(3) >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 18 03:50:02 PST 2002 >Closed-Date: >Last-Modified: >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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message