From 9ccd260842d246261fa5c29b7a6f56d2811a75d9 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 15 Aug 2016 07:25:18 -0600 Subject: [PATCH] Make sure we print an error message to stderr (and not just send mail) if do_logfile() fails. Bug #751 --- plugins/sudoers/logging.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/sudoers/logging.c b/plugins/sudoers/logging.c index 8d4de9911..32e98f44d 100644 --- a/plugins/sudoers/logging.c +++ b/plugins/sudoers/logging.c @@ -157,13 +157,21 @@ do_logfile(const char *msg) fp = fopen(def_logfile, "a"); (void) umask(oldmask); if (fp == NULL) { + int saved_errno = errno; + send_mail(_("unable to open log file: %s: %s"), - def_logfile, strerror(errno)); + def_logfile, strerror(saved_errno)); + sudo_warnx(U_("unable to open log file: %s: %s"), + def_logfile, strerror(saved_errno)); goto done; } if (!sudo_lock_file(fileno(fp), SUDO_LOCK)) { + int saved_errno = errno; + send_mail(_("unable to lock log file: %s: %s"), - def_logfile, strerror(errno)); + def_logfile, strerror(saved_errno)); + sudo_warnx(U_("unable to lock log file: %s: %s"), + def_logfile, strerror(saved_errno)); goto done; } @@ -191,8 +199,16 @@ do_logfile(const char *msg) } free(full_line); (void) fflush(fp); - if (!ferror(fp)) - rval = true; + if (ferror(fp)) { + int saved_errno = errno; + + send_mail(_("unable to write log file: %s: %s"), + def_logfile, strerror(saved_errno)); + sudo_warnx(U_("unable to write log file: %s: %s"), + def_logfile, strerror(saved_errno)); + goto done; + } + rval = true; done: if (fp != NULL) @@ -433,6 +449,7 @@ vlog_warning(int flags, const char *fmt, va_list ap) len = vasprintf(&message, _(fmt), ap); } if (len == -1) { + sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); rval = false; goto done; } @@ -453,6 +470,7 @@ vlog_warning(int flags, const char *fmt, va_list ap) free(message); if (logline == NULL) { rval = false; + sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); goto done; } } -- 2.50.1