From 13a8eb257b4c0056959924e16a3d8f45ccdffac2 Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 1 Jul 2016 15:47:15 +0000 Subject: [PATCH] Avoid printing f->f_lasttime and/or f->f_prevhost if they are empty. This fixes a long-standing issue where syslogd would print 15 NUL bytes followed by two blank spaces before the log message for warnings generated while parsing syslog.conf. OK bluhm@ --- usr.sbin/syslogd/syslogd.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index e916ef12e1c..a3f83d614d3 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.206 2016/07/01 15:00:48 millert Exp $ */ +/* $OpenBSD: syslogd.c,v 1.207 2016/07/01 15:47:15 millert Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -1738,20 +1738,36 @@ fprintlog(struct filed *f, int flags, char *msg) v->iov_base = ""; v->iov_len = 0; v++; - } else { + } else if (f->f_lasttime[0] != '\0') { v->iov_base = f->f_lasttime; v->iov_len = 15; v++; v->iov_base = " "; v->iov_len = 1; v++; + } else { + v->iov_base = ""; + v->iov_len = 0; + v++; + v->iov_base = ""; + v->iov_len = 0; + v++; + } + if (f->f_prevhost[0] != '\0') { + v->iov_base = f->f_prevhost; + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = " "; + v->iov_len = 1; + v++; + } else { + v->iov_base = ""; + v->iov_len = 0; + v++; + v->iov_base = ""; + v->iov_len = 0; + v++; } - v->iov_base = f->f_prevhost; - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = " "; - v->iov_len = 1; - v++; if (msg) { v->iov_base = msg; -- 2.20.1