--- syslog.c.orig Thu Dec 18 11:36:14 2003 +++ syslog.c Thu Dec 18 11:59:46 2003 @@ -98,7 +98,8 @@ register char *p; time_t now; int fd, saved_errno; - char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0; + char tbuf[2048], fmt_cpy[1024], *stdp; + int n; saved_errno = errno; @@ -114,17 +115,19 @@ /* build the message */ (void)time(&now); - (void)sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4); - for (p = tbuf; *p; ++p); - if (LogStat & LOG_PERROR) - stdp = p; + n = sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4); + if (n < 0) + n = 0; + p = tbuf + n; + stdp = p; if (LogTag) { (void)strcpy(p, LogTag); for (; *p; ++p); } if (LogStat & LOG_PID) { - (void)sprintf(p, "[%d]", getpid()); - for (; *p; ++p); + n = sprintf(p, "[%d]", getpid()); + if (n > 0) + p += n; } if (LogTag) { *p++ = ':'; @@ -149,9 +152,11 @@ *t1 = '\0'; } - (void)vsprintf(p, fmt_cpy, ap); + n = vsprintf(p, fmt_cpy, ap); + if (n > 0) + p += n; - cnt = strlen(tbuf); + cnt = p - tbuf; /* output to stderr if requested */ if (LogStat & LOG_PERROR) { @@ -159,7 +164,7 @@ register struct iovec *v = iov; v->iov_base = stdp; - v->iov_len = cnt - (stdp - tbuf); + v->iov_len = p - stdp; ++v; v->iov_base = "\n"; v->iov_len = 1; --- syslogd.c.orig Thu Dec 18 12:03:19 2003 +++ syslogd.c Thu Dec 18 12:13:27 2003 @@ -1257,13 +1257,14 @@ int count, i; char *p, *q; char **result = NULL; + size_t l; p = list; /* strip off trailing delimiters */ - while (p[strlen(p)-1] == LIST_DELIMITER) { + while (l = strlen(p)-1, p[l] == LIST_DELIMITER) { count--; - p[strlen(p)-1] = '\0'; + p[l] = '\0'; } /* cut off leading delimiters */ while (p[0] == LIST_DELIMITER) { @@ -1360,11 +1361,16 @@ tmpline[0] = '\0'; if ( parts[fd] != (char *) 0 ) { + size_t msglen; + size_t tmplinelen; + dprintf("Including part from messages.\n"); strcpy(tmpline, parts[fd]); free(parts[fd]); parts[fd] = (char *) 0; - if ( (strlen(msg) + strlen(tmpline)) > MAXLINE ) + msglen = strlen(msg); + tmplinelen = strlen(tmpline); + if ( (msglen + tmplinelen) > MAXLINE ) { logerror("Cannot glue message parts together"); printline(hname, tmpline); @@ -1374,9 +1380,10 @@ { dprintf("Previous: %s\n", tmpline); dprintf("Next: %s\n", msg); - strcat(tmpline, msg); /* length checked above */ + /* length checked above */ + strcpy(tmpline + tmplinelen, msg); printline(hname, tmpline); - if ( (strlen(msg) + 1) == len ) + if ( msglen + 1 == len ) return; else start = strchr(msg, '\0') + 1; @@ -1546,18 +1553,16 @@ omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM)); #endif + (void) time(&now); /* * Check to see if msg looks non-standard. */ msglen = strlen(msg); if (msglen < 16 || msg[3] != ' ' || msg[6] != ' ' || - msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') + msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { flags |= ADDDATE; - - (void) time(&now); - if (flags & ADDDATE) timestamp = ctime(&now) + 4; - else { + } else { timestamp = msg; msg += 16; msglen -= 16;