mailing list of musl libc
 help / color / mirror / code / Atom feed
* Possible bug in openlog()
@ 2015-01-07 21:04 Dima Krasner
  0 siblings, 0 replies; 4+ messages in thread
From: Dima Krasner @ 2015-01-07 21:04 UTC (permalink / raw)
  To: musl; +Cc: dalias


[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Possible bug in openlog()
@ 2015-01-05 13:39 Dima Krasner
  2015-01-05 15:46 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Dima Krasner @ 2015-01-05 13:39 UTC (permalink / raw)
  To: musl


[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-07 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-07 21:04 Possible bug in openlog() Dima Krasner
  -- 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

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).