From 1018d4a7f4035ab3bc8fe97af586b9f821637d75 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 22 Nov 2021 04:27:18 +0100 Subject: [PATCH] Avoid NULL pointer to vsnprintf() GLIBC is friendly enough to check for NULL and replace segfault with "(null)", but other C-libs may not handle it as gracefully. Signed-off-by: Joachim Wiberg --- src/syslogd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index cfd5317..6ea4719 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -1698,9 +1698,12 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags) f->f_prevcount = 0; } -#define fmtlogit(bm) logit("%s(%d, 0x%02x, %s, %s, %s, %s, %s, %s)", __func__, \ - bm->pri, bm->flags, bm->hostname, bm->app_name, \ - bm->proc_id, bm->msgid, bm->sd, bm->msg) +#define fmtlogit(bm) logit("%s(%d, 0x%02x, %s, %s, %s, %s, %s, %s)", __func__, \ + bm->pri, bm->flags, bm->hostname ? bm->hostname : "-", \ + bm->app_name ? bm->app_name : "-", \ + bm->proc_id ? bm->proc_id : "-", \ + bm->msgid ? bm->msgid : "-", \ + bm->sd ? bm->sd : "-", bm->msg ? bm->msg : "-") static int fmt3164(struct buf_msg *buffer, char *fmt, struct iovec *iov, size_t iovmax) {