Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jan 2002 12:46:51 +0100 (CET)
From:      Hartmut Brandt <brandt@fokus.gmd.de>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/34022: syslog(3) clobbers static storage used by ctime(3)
Message-ID:  <200201181146.g0IBkp672380@fokus.gmd.de>

next in thread | raw e-mail | index | archive | help

>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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201181146.g0IBkp672380>