Save errno before calling asprintf(), since asprintf() may touch errno,

which will cause syslog() to log the wrong error message if the format
string contains %m.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@537 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2012-03-31 16:20:13 +00:00
parent 74c787f664
commit 783a383e4b
1 changed files with 5 additions and 2 deletions

View File

@ -39,11 +39,10 @@
# include "config.h"
#endif
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <security/pam_appl.h>
@ -101,6 +100,7 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
va_list ap;
char *format;
int priority;
int serrno;
switch (level) {
case PAM_LOG_DEBUG:
@ -120,10 +120,13 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
break;
}
va_start(ap, fmt);
serrno = errno;
if (asprintf(&format, "in %s(): %s", func, fmt) > 0) {
errno = serrno;
vsyslog(priority, format, ap);
FREE(format);
} else {
errno = serrno;
vsyslog(priority, fmt, ap);
}
va_end(ap);