Re: logger: Segmentation fault when reading from stdin and writing to socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 6 Apr 2015, Patrick Plagwitz wrote:

> I have noticed a bug within the development version of the logger
> utility (misc-utils/logger.c).
> When reading messages from stdin (so that logger_stdin is called) and
> outputting to a TCP/UDP socket (inet_socket) logger SEGFAULTs:
> 
> $ echo foo | logger -n localhost
> Segmentation fault (core dumped)
> 
> This bug happens because, in this combination, the syslog header isn't
> generated before calling strlen() on it and has probably been introduced
> somewhere when separating writing the header and writing the message.
> Calling generate_syslog_header in logger_open also for inet sockets
> fixes this.
> The attached patch does just that.
> 
> On an unrelated note, the write_output function leaks memory by not
> freeing the buf local variable.

Hi Patrick and others,

The below appears to fix the issue. And this reminds me logger(1) ought to 
have 'remote' logging tests writing to netcat(1) server.

--->8----
From: Sami Kerola <kerolasa@xxxxxx>
Date: Mon, 6 Apr 2015 22:42:54 +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.

Reported-by: Patrick Plagwitz <patrick.plagwitz@xxxxxx>
Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 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 edc9483..753cd7f 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.3.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux