From c3d0fb44481a973b9328546c5414637edff03e4f Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 1 May 2020 10:56:09 +0200 Subject: [PATCH] Avoid throwing an exception in Logger::log(). Throwing an exception in the logger, almost cetainly will cause trouble. Coverity 1428667 shows this can happen in LdapBackend::~LdapBackend(). --- pdns/logger.cc | 12 +++++++++--- pdns/logger.hh | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pdns/logger.cc b/pdns/logger.cc index 61dcf28f5f..6804b39979 100644 --- a/pdns/logger.cc +++ b/pdns/logger.cc @@ -50,7 +50,7 @@ Logger& getLogger() return log; } -void Logger::log(const string &msg, Urgency u) +void Logger::log(const string &msg, Urgency u) noexcept { #ifndef RECURSOR bool mustAccount(false); @@ -113,8 +113,14 @@ void Logger::log(const string &msg, Urgency u) } #ifndef RECURSOR - if(mustAccount) - S.ringAccount("logmessages",msg); + if(mustAccount) { + try { + S.ringAccount("logmessages",msg); + } + catch (const runtime_error& e) { + cerr << e.what() << endl; + } + } #endif } diff --git a/pdns/logger.hh b/pdns/logger.hh index 38689e2d5a..e8c4da7019 100644 --- a/pdns/logger.hh +++ b/pdns/logger.hh @@ -45,7 +45,7 @@ public: \param msg Message you wish to log \param u Urgency of the message you wish to log */ - void log(const string &msg, Urgency u=Notice); + void log(const string &msg, Urgency u=Notice) noexcept; void setFacility(int f){d_facility=f;open();} //!< Choose logging facility void setFlag(int f){flags|=f;open();} //!< set a syslog flag -- 2.47.2