From 75030d06769539cf2b6ccf6cb237fe8917efccd2 Mon Sep 17 00:00:00 2001 From: David Malone Date: Sat, 29 May 2004 23:40:30 +0000 Subject: [PATCH] Some string fixes. 1) Use strncpy on strings out of utmp. 2) Avoid running off the start of one string while removing white space. (I've used slightly different code to OpenBSD here.) 3) Ignore trailing spaces in the priority. PR: 67139 Submitted by: Xin LI Obtained from: OpenBSD --- usr.sbin/syslogd/syslogd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 146dfb02eb13..6c5106eb9e0b 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1236,7 +1236,9 @@ wallmsg(struct filed *f, struct iovec *iov) while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) { if (ut.ut_name[0] == '\0') continue; - (void)strlcpy(line, ut.ut_line, sizeof(line)); + /* We must use strncpy since ut_* may not be NUL terminated. */ + strncpy(line, ut.ut_line, sizeof(line) - 1); + line[sizeof(line) - 1] = '\0'; if (f->f_type == F_WALL) { if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) != NULL) { errno = 0; /* already in msg */ @@ -1544,9 +1546,8 @@ init(int signo) prog[i] = 0; continue; } - for (p = strchr(cline, '\0'); isspace(*--p);) - continue; - *++p = '\0'; + for (i = strlen(cline) - 1; i >= 0 && isspace(cline[i]); i--) + cline[i] = '\0'; f = (struct filed *)calloc(1, sizeof(*f)); if (f == NULL) { logerror("calloc"); @@ -1724,6 +1725,10 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host) pri = LOG_PRIMASK + 1; pri_cmp = PRI_LT | PRI_EQ | PRI_GT; } else { + /* Ignore trailing spaces. */ + for (i = strlen(buf) - 1; i >= 0 && buf[i] == ' '; i--) + buf[i] = '\0'; + pri = decode(buf, prioritynames); if (pri < 0) { (void)snprintf(ebuf, sizeof ebuf,