Chris Browne cbbrowne at lists.slony.info
Thu Feb 11 13:13:26 PST 2010
Update of /home/cvsd/slony1/slony1-engine/src/slon
In directory main.slony.info:/tmp/cvs-serv25332

Modified Files:
      Tag: REL_1_2_STABLE
	misc.c 
Log Message:
Gwyn Connor pointed out a sprintf() abuse...

When log entries are generated, we're passing outbuf both as buffer and as
a source of data.  Behaviour is undefined on some systems, notably including
Gentoo Linux.

Change:  Make sure there are buffers for the date + process, fill them, and
reference them.

- Apply to 1.2 branch


Index: misc.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/misc.c,v
retrieving revision 1.22.2.4
retrieving revision 1.22.2.5
diff -C 2 -d -r1.22.2.4 -r1.22.2.5
*** misc.c	9 Dec 2009 19:44:38 -0000	1.22.2.4
--- misc.c	11 Feb 2010 21:13:24 -0000	1.22.2.5
***************
*** 84,88 ****
  	char	   *level_c = NULL;
  
! 	char		time_buf[128];
  	time_t		stamp_time = time(NULL);
  
--- 84,89 ----
  	char	   *level_c = NULL;
  
! 	char		time_buf[128];   /* Buffer to hold timestamp */
! 	char        ps_buf[20];      /* Buffer to hold PID */
  	time_t		stamp_time = time(NULL);
  
***************
*** 164,173 ****
  		strftime(time_buf, sizeof(time_buf), log_timestamp_format, localtime(&stamp_time));
  		sprintf(outbuf, "%s ", time_buf);
  	}
  	if (logpid == true)
  	{
  		sprintf(outbuf, "%s[%d] ", outbuf, slon_pid);
  	}
! 	sprintf(outbuf, "%s%-6.6s ", outbuf, level_c);
  
  	off = strlen(outbuf);
--- 165,178 ----
  		strftime(time_buf, sizeof(time_buf), log_timestamp_format, localtime(&stamp_time));
  		sprintf(outbuf, "%s ", time_buf);
+ 	} else {
+ 		time_buf[0] = (char) 0;
  	}
  	if (logpid == true)
  	{
  		sprintf(outbuf, "%s[%d] ", outbuf, slon_pid);
+ 	} else {
+ 		ps_buf[0] = (char) 0;
  	}
! 	sprintf(outbuf, "%s%s%-6.6s ", time_buf, ps_buf, level_c);
  
  	off = strlen(outbuf);



More information about the Slony1-commit mailing list