diff options
author | peter <peter@FreeBSD.org> | 1995-10-05 00:11:15 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1995-10-05 00:11:15 +0000 |
commit | 4fb58f1ed15303631266730af1abfe740ea26a22 (patch) | |
tree | ad41a496deeec936619768282a2278e08b145ff9 /lib/libc | |
parent | 3b5c5d69f06e0948fc3c7adee751281293d89881 (diff) | |
download | FreeBSD-src-4fb58f1ed15303631266730af1abfe740ea26a22.zip FreeBSD-src-4fb58f1ed15303631266730af1abfe740ea26a22.tar.gz |
Fix the problem that I aroused with the last commit..
What was happening, is if syslogd was not running, syslog() would do
a strcat("\r\n") on a non-null-terminated buffer, and write it to the console.
This meant that sometimes extra characters could be written to the console
during boot, depending on the stack contents.
This totally avoids the potential problem by using writev() like the rest
of the does, and avoid modifying the buffer after the trouble we've gone to
to carefully protect it.
This is actually a trivial fix, in spite of the long commit message.. :-)
It only appeared during boot and shutdown with syslogd stopped.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/syslog.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 3c50e25..dd5a8cc 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -241,10 +241,16 @@ vsyslog(pri, fmt, ap) */ if (LogStat & LOG_CONS && (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) { - (void)strcat(tbuf, "\r\n"); - cnt += 2; - p = index(tbuf, '>') + 1; - (void)write(fd, p, cnt - (p - tbuf)); + struct iovec iov[2]; + register struct iovec *v = iov; + + p = strchr(tbuf, '>') + 1; + v->iov_base = p; + v->iov_len = cnt - (p - tbuf); + ++v; + v->iov_base = "\r\n"; + v->iov_len = 2; + (void)writev(fd, iov, 2); (void)close(fd); } } |