From bd5903509d476dfce5828a4eed1afb727d1f2150 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 15 Nov 2019 08:26:21 +0100 Subject: [PATCH] syslogd: Fix RFC3164 formatting, no space after field Signed-off-by: Joachim Nilsson --- src/syslogd.c | 11 +++++------ src/syslogd.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index ee951f9..9857864 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -1533,7 +1533,7 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags) if (f->f_type == F_FILE) logrotate(f); - if (writev(f->f_file, &iov[2], iovcnt - 2) < 0) { + if (writev(f->f_file, &iov[1], iovcnt - 1) < 0) { int e = errno; /* If a named pipe is full, just ignore it for now */ @@ -1580,7 +1580,7 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags) f->f_time = now; logit("\n"); pushiov(iov, iovcnt, "\r\n"); - wallmsg(f, &iov[2], iovcnt - 2); + wallmsg(f, &iov[1], iovcnt - 1); break; } /* switch */ @@ -1598,9 +1598,9 @@ static int fmt3164(struct buf_msg *buffer, char *fmt, struct iovec *iov, size_t fmtlogit(buffer); + /* Notice difference to RFC5424, in RFC3164 there is *no* space! */ snprintf(buffer->pribuf, sizeof(buffer->pribuf), "<%d>", buffer->pri); pushiov(iov, i, buffer->pribuf); - pushsp(iov, i); /* * sysklogd < 2.0 had the traditional BSD format for remote syslog @@ -1653,10 +1653,9 @@ static int fmt5424(struct buf_msg *buffer, char *fmt, struct iovec *iov, size_t usec /= 10; } - /* RFC 5424 defines itself as v1 */ - snprintf(buffer->pribuf, sizeof(buffer->pribuf), "<%d>1", buffer->pri); + /* RFC 5424 defines itself as v1, notice space before time, c.f. RFC3164 */ + snprintf(buffer->pribuf, sizeof(buffer->pribuf), "<%d>1 ", buffer->pri); pushiov(iov, i, buffer->pribuf); - pushsp(iov, i); pushiov(iov, i, buffer->timebuf); pushsp(iov, i); diff --git a/src/syslogd.h b/src/syslogd.h index 8f372b8..2b4be3c 100644 --- a/src/syslogd.h +++ b/src/syslogd.h @@ -223,7 +223,7 @@ struct logtime { /* message buffer container used for processing, formatting, and queueing */ struct buf_msg { int pri; - char pribuf[7]; + char pribuf[8]; int flags; struct logtime timestamp; char timebuf[33];