mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix the %m specifier in syslog
@ 2014-07-09 12:34 Clément Vasseur
  2014-07-12  0:04 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Clément Vasseur @ 2014-07-09 12:34 UTC (permalink / raw)
  To: musl

errno must be saved upon vsyslog entry, otherwise its value could be
changed by some libc function before reaching the %m handler in
vsnprintf.
---
 src/misc/syslog.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 1cd61ce..57f1d75 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <string.h>
 #include <pthread.h>
+#include <errno.h>
 #include "libc.h"
 #include "atomic.h"
 
@@ -76,6 +77,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	time_t now;
 	struct tm tm;
 	char buf[256];
+	int errno_save = errno;
 	int pid;
 	int l, l2;
 
@@ -93,6 +95,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	pid = (log_opt & LOG_PID) ? getpid() : 0;
 	l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
 		priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
+	errno = errno_save;
 	l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
 	if (l2 >= 0) {
 		if (l2 >= sizeof buf - l) l = sizeof buf - 1;
-- 
2.0.1



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

end of thread, other threads:[~2014-07-12 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09 12:34 [PATCH] fix the %m specifier in syslog Clément Vasseur
2014-07-12  0:04 ` Rich Felker
2014-07-12  6:52   ` Szabolcs Nagy
2014-07-12 13:55     ` 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).