mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Dima Krasner <dima@dimakrasner.com>
To: musl@lists.openwall.com
Cc: dalias@aerifal.cx
Subject: Possible bug in openlog()
Date: Wed, 7 Jan 2015 23:04:49 +0200	[thread overview]
Message-ID: <20150107230449.a74a6fb52c6f34d889e27081@dimakrasner.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 507 bytes --]

Hi,

I think I found a bug in openlog() - it's racy. If syslogd is started after openlog() is called, there's a small chance that the socket will remain open, while connect() failed. Then, syslog() does not call openlog() again, because it only checks whether the socket file descriptor is valid.

Therefore, all syslog() messages are dropped silently and nothing gets logged. I attached a fix.

Can you merge it or provide feedback, please?

Thank you,
Dima

-- 
Dima Krasner, dimakrasner.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: musl-syslog-retry.patch --]
[-- Type: text/x-diff; name="musl-syslog-retry.patch", Size: 617 bytes --]

diff -rup musl-1.0.4-orig/src/misc/syslog.c musl-1.0.4/src/misc/syslog.c
--- musl-1.0.4-orig/src/misc/syslog.c	2015-01-05 15:15:35.349015771 +0200
+++ musl-1.0.4/src/misc/syslog.c	2015-01-05 15:21:30.525024212 +0200
@@ -46,7 +46,11 @@ void closelog(void)
 static void __openlog()
 {
 	log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
-	if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr);
+	if (log_fd < 0) return;
+	if (connect(log_fd, (void *)&log_addr, sizeof log_addr) < 0) {
+		close(log_fd);
+		log_fd = -1;
+	}
 }
 
 void openlog(const char *ident, int opt, int facility)

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

             reply	other threads:[~2015-01-07 21:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 21:04 Dima Krasner [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-05 13:39 Dima Krasner
2015-01-05 15:46 ` Rich Felker
2015-01-06 17:40   ` Rich Felker

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=20150107230449.a74a6fb52c6f34d889e27081@dimakrasner.com \
    --to=dima@dimakrasner.com \
    --cc=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).