From 9daa70d8409b46c5cfd0100400fdd722b9f40bb9 Mon Sep 17 00:00:00 2001 From: Patrick Plagwitz Date: Mon, 6 Apr 2015 22:50:46 +0100 Subject: [PATCH] logger: generate header when reading message from stdin This change fixes crashing error, that ought not to be simply avoided. $ echo foo | logger -n localhost Segmentation fault (core dumped) If the ctl->hdr is just checked not to be NULL syslog message will not have valid header, so generating such is not optional when reading message from stdin and writing it to remote destination. Reviewed-by: Bernhard Voelker Signed-off-by: Patrick Plagwitz Signed-off-by: Sami Kerola --- misc-utils/logger.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/misc-utils/logger.c b/misc-utils/logger.c index edc94836b0..753cd7f995 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -582,14 +582,14 @@ static void logger_open(struct logger_ctl *ctl) ctl->fd = inet_socket(ctl->server, ctl->port, ctl->socket_type); if (!ctl->syslogfp) ctl->syslogfp = syslog_rfc5424_header; - return; - } - if (!ctl->unix_socket) - ctl->unix_socket = _PATH_DEVLOG; + } else { + if (!ctl->unix_socket) + ctl->unix_socket = _PATH_DEVLOG; - ctl->fd = unix_socket(ctl, ctl->unix_socket, ctl->socket_type); - if (!ctl->syslogfp) - ctl->syslogfp = syslog_local_header; + ctl->fd = unix_socket(ctl, ctl->unix_socket, ctl->socket_type); + if (!ctl->syslogfp) + ctl->syslogfp = syslog_local_header; + } if (!ctl->tag) ctl->tag = xgetlogin(); generate_syslog_header(ctl); -- 2.47.2