]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: generate header when reading message from stdin
authorPatrick Plagwitz <patrick.plagwitz@fau.de>
Mon, 6 Apr 2015 21:50:46 +0000 (22:50 +0100)
committerSami Kerola <sami.kerola@lastminute.com>
Tue, 7 Apr 2015 07:51:05 +0000 (08:51 +0100)
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 <mail@bernhard-voelker.de>
Signed-off-by: Patrick Plagwitz <patrick.plagwitz@fau.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c

index edc94836b0b25b567710e2456f27eca46166b962..753cd7f9951e84ff371db4771337e3e3030d69d2 100644 (file)
@@ -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);