From: Patrick Plagwitz <patrick.plagwitz@fau.de>
To: util-linux@vger.kernel.org
Subject: logger: Segmentation fault when reading from stdin and writing to socket
Date: Mon, 06 Apr 2015 04:02:21 +0200 [thread overview]
Message-ID: <5521E92D.2090404@fau.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Hi,
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.
Patrick
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch; name="patch.diff", Size: 855 bytes --]
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index edc9483..fbe8ced 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -582,14 +582,15 @@ 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;
+ } 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;
}
- 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;
if (!ctl->tag)
ctl->tag = xgetlogin();
generate_syslog_header(ctl);
next reply other threads:[~2015-04-06 2:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-06 2:02 Patrick Plagwitz [this message]
2015-04-06 21:50 ` logger: Segmentation fault when reading from stdin and writing to socket Sami Kerola
2015-04-07 6:36 ` Bernhard Voelker
2015-04-07 8:00 ` Sami Kerola
2015-04-07 8:43 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5521E92D.2090404@fau.de \
--to=patrick.plagwitz@fau.de \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox