summaryrefslogtreecommitdiffstats
path: root/usr.sbin/syslogd
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2004-05-29 23:40:30 +0000
committerdwmalone <dwmalone@FreeBSD.org>2004-05-29 23:40:30 +0000
commit24cd00695a1b9fe78296cb4eef0b18e82837aee9 (patch)
treebc51e465bd66fb9ec4e5b53ab647c0565e936cde /usr.sbin/syslogd
parentce2d6884e8fc1fa3b44565763cc15603de852a04 (diff)
downloadFreeBSD-src-24cd00695a1b9fe78296cb4eef0b18e82837aee9.zip
FreeBSD-src-24cd00695a1b9fe78296cb4eef0b18e82837aee9.tar.gz
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 <delphij@FreeBSD.org.cn> Obtained from: OpenBSD
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r--usr.sbin/syslogd/syslogd.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 146dfb0..6c5106e 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,
OpenPOWER on IntegriCloud