Date: Tue, 29 Aug 1995 00:49:50 -0700 From: Paul Traina <pst> To: security Subject: please code review proposed fix for syslog problem Message-ID: <199508290749.AAA16552@freefall.FreeBSD.org>
index | next in thread | raw e-mail
Index: lib/libc/gen/syslog.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v
retrieving revision 1.2
diff -c -r1.2 syslog.c
*** 1.2 1995/05/02 17:46:30
--- syslog.c 1995/08/29 07:49:14
***************
*** 101,106 ****
--- 101,108 ----
char *stdp, tbuf[2048], fmt_cpy[1024];
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
+ #define SPACELEFT(X) (sizeof(tbuf) - ((X) - tbuf))
+
/* Check for invalid bits. */
if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
syslog(INTERNALLOG,
***************
*** 120,136 ****
/* Build the message. */
(void)time(&now);
! p = tbuf + sprintf(tbuf, "<%d>", pri);
! p += strftime(p, sizeof (tbuf) - (p - tbuf), "%h %e %T ",
! localtime(&now));
if (LogStat & LOG_PERROR)
stdp = p;
if (LogTag == NULL)
LogTag = __progname;
if (LogTag != NULL)
! p += sprintf(p, "%s", LogTag);
if (LogStat & LOG_PID)
! p += sprintf(p, "[%d]", getpid());
if (LogTag != NULL) {
*p++ = ':';
*p++ = ' ';
--- 122,137 ----
/* Build the message. */
(void)time(&now);
! p = tbuf + snprintf(tbuf, sizeof(tbuf), "<%d>", pri);
! p += strftime(p, SPACELEFT(p), "%h %e %T ", localtime(&now));
if (LogStat & LOG_PERROR)
stdp = p;
if (LogTag == NULL)
LogTag = __progname;
if (LogTag != NULL)
! p += snprintf(p, SPACELEFT(p), "%s", LogTag);
if (LogStat & LOG_PID)
! p += snprintf(p, SPACELEFT(p), "[%d]", getpid());
if (LogTag != NULL) {
*p++ = ':';
*p++ = ' ';
***************
*** 140,151 ****
for (t = fmt_cpy; ch = *fmt; ++fmt)
if (ch == '%' && fmt[1] == 'm') {
++fmt;
! t += sprintf(t, "%s", strerror(saved_errno));
} else
*t++ = ch;
*t = '\0';
! p += vsprintf(p, fmt_cpy, ap);
cnt = p - tbuf;
/* Output to stderr if requested. */
--- 141,153 ----
for (t = fmt_cpy; ch = *fmt; ++fmt)
if (ch == '%' && fmt[1] == 'm') {
++fmt;
! t += snprintf(t, sizeof(fmt_cpy) - (t - fmt_cpy), "%s",
! strerror(saved_errno));
} else
*t++ = ch;
*t = '\0';
! p += vsnprintf(p, SPACELEFT(p), fmt_cpy, ap);
cnt = p - tbuf;
/* Output to stderr if requested. */
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199508290749.AAA16552>
