From c8edabb035d4cd52280235f20b5d40d533c4386f Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 30 Oct 2015 14:36:01 +0000 Subject: [PATCH 1/2] Fix memory leak when reading invalid znc.conf Found by https://scan.coverity.com/ --- src/IRCNetwork.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index a022b0e9..3d6221c0 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -472,6 +472,7 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) CUtils::PrintError(sError); CZNC::DumpConfig(pSubConf); + delete pChan; return false; } From 096dc5b320b380d1a1f2d4de574e34fe93a57589 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 30 Oct 2015 14:52:51 +0000 Subject: [PATCH 2/2] Fix some unitialized fields in modules. They are not used before OnLoad anyway, but Coverity will be happier. --- modules/adminlog.cpp | 2 +- modules/clientnotify.cpp | 4 ++-- modules/ctcpflood.cpp | 11 ++++------- modules/cyrusauth.cpp | 14 +++++++------- modules/fail2ban.cpp | 2 +- modules/keepnick.cpp | 2 +- modules/kickrejoin.cpp | 2 +- modules/notes.cpp | 6 +++--- modules/q.cpp | 20 ++++++++++---------- modules/sasl.cpp | 2 +- 10 files changed, 31 insertions(+), 34 deletions(-) diff --git a/modules/adminlog.cpp b/modules/adminlog.cpp index f73c4834..d5af21a2 100644 --- a/modules/adminlog.cpp +++ b/modules/adminlog.cpp @@ -174,7 +174,7 @@ private: LOG_TO_SYSLOG = 1 << 1, LOG_TO_BOTH = LOG_TO_FILE | LOG_TO_SYSLOG }; - LogMode m_eLogMode; + LogMode m_eLogMode = LOG_TO_FILE; CString m_sLogFile; }; diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index 40d96d34..ca55efd3 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -22,8 +22,8 @@ using std::set; class CClientNotifyMod : public CModule { protected: CString m_sMethod; - bool m_bNewOnly; - bool m_bOnDisconnect; + bool m_bNewOnly{}; + bool m_bOnDisconnect{}; set m_sClientsSeen; diff --git a/modules/ctcpflood.cpp b/modules/ctcpflood.cpp index 45e3d142..c727e976 100644 --- a/modules/ctcpflood.cpp +++ b/modules/ctcpflood.cpp @@ -20,9 +20,6 @@ class CCtcpFloodMod : public CModule { public: MODCONSTRUCTOR(CCtcpFloodMod) { - m_tLastCTCP = 0; - m_iNumCTCP = 0; - AddHelpCommand(); AddCommand("Secs", static_cast(&CCtcpFloodMod::OnSecsCommand), "", "Set seconds limit"); AddCommand("Lines", static_cast(&CCtcpFloodMod::OnLinesCommand), "", "Set lines limit"); @@ -130,11 +127,11 @@ public: } private: - time_t m_tLastCTCP; - unsigned int m_iNumCTCP; + time_t m_tLastCTCP = 0; + unsigned int m_iNumCTCP = 0; - time_t m_iThresholdSecs; - unsigned int m_iThresholdMsgs; + time_t m_iThresholdSecs{}; + unsigned int m_iThresholdMsgs{}; }; template<> void TModInfo(CModInfo& Info) { diff --git a/modules/cyrusauth.cpp b/modules/cyrusauth.cpp index 6d4e61a1..cba01a0b 100644 --- a/modules/cyrusauth.cpp +++ b/modules/cyrusauth.cpp @@ -31,6 +31,13 @@ public: MODCONSTRUCTOR(CSASLAuthMod) { m_Cache.SetTTL(60000/*ms*/); + m_cbs[0].id = SASL_CB_GETOPT; + m_cbs[0].proc = reinterpret_cast(CSASLAuthMod::getopt); + m_cbs[0].context = this; + m_cbs[1].id = SASL_CB_LIST_END; + m_cbs[1].proc = NULL; + m_cbs[1].context = NULL; + AddHelpCommand(); AddCommand("CreateUser", static_cast(&CSASLAuthMod::CreateUserCommand), "[yes|no]"); @@ -77,13 +84,6 @@ public: return false; } - m_cbs[0].id = SASL_CB_GETOPT; - m_cbs[0].proc = reinterpret_cast(CSASLAuthMod::getopt); - m_cbs[0].context = this; - m_cbs[1].id = SASL_CB_LIST_END; - m_cbs[1].proc = NULL; - m_cbs[1].context = NULL; - return true; } diff --git a/modules/fail2ban.cpp b/modules/fail2ban.cpp index beb4f9ff..2fbe862f 100644 --- a/modules/fail2ban.cpp +++ b/modules/fail2ban.cpp @@ -100,7 +100,7 @@ public: private: TCacheMap m_Cache; - unsigned int m_uiAllowedFailed; + unsigned int m_uiAllowedFailed{}; }; template<> void TModInfo(CModInfo& Info) { diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 0c03ead8..207f4f7f 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -192,7 +192,7 @@ public: private: // If this is NULL, we are turned off for some reason - CKeepNickTimer* m_pTimer; + CKeepNickTimer* m_pTimer = nullptr; }; CKeepNickTimer::CKeepNickTimer(CKeepNickMod *pMod) : CTimer(pMod, 30, 0, diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index b43d5720..a009bf5f 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -47,7 +47,7 @@ protected: class CRejoinMod : public CModule { private: - unsigned int delay; + unsigned int delay = 10; public: MODCONSTRUCTOR(CRejoinMod) { diff --git a/modules/notes.cpp b/modules/notes.cpp index b4a720c1..f8e2dbf9 100644 --- a/modules/notes.cpp +++ b/modules/notes.cpp @@ -19,7 +19,7 @@ using std::stringstream; class CNotesMod : public CModule { - bool bShowNotesOnLogin; + bool m_bShowNotesOnLogin{}; void ListCommand(const CString &sLine) { ListNotes(); @@ -85,14 +85,14 @@ public: virtual ~CNotesMod() {} virtual bool OnLoad(const CString& sArgs, CString& sMessage) override { - bShowNotesOnLogin = !sArgs.Equals("-disableNotesOnLogin"); + m_bShowNotesOnLogin = !sArgs.Equals("-disableNotesOnLogin"); return true; } virtual CString GetWebMenuTitle() override { return "Notes"; } virtual void OnClientLogin() override { - if (bShowNotesOnLogin) { + if (m_bShowNotesOnLogin) { ListNotes(true); } } diff --git a/modules/q.cpp b/modules/q.cpp index a64e756b..263e488d 100644 --- a/modules/q.cpp +++ b/modules/q.cpp @@ -372,11 +372,11 @@ public: } private: - bool m_bCloaked; - bool m_bAuthed; - bool m_bRequestedWhoami; - bool m_bRequestedChallenge; - bool m_bCatchResponse; + bool m_bCloaked{}; + bool m_bAuthed{}; + bool m_bRequestedWhoami{}; + bool m_bRequestedChallenge{}; + bool m_bCatchResponse{}; MCString m_msChanModes; void PutQ(const CString& sMessage) { @@ -590,11 +590,11 @@ private: /* Settings */ CString m_sUsername; CString m_sPassword; - bool m_bUseCloakedHost; - bool m_bUseChallenge; - bool m_bRequestPerms; - bool m_bJoinOnInvite; - bool m_bJoinAfterCloaked; + bool m_bUseCloakedHost{}; + bool m_bUseChallenge{}; + bool m_bRequestPerms{}; + bool m_bJoinOnInvite{}; + bool m_bJoinAfterCloaked{}; void SetUsername(const CString& sUsername) { m_sUsername = sUsername; diff --git a/modules/sasl.cpp b/modules/sasl.cpp index b068a42f..4f2fc3de 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -61,7 +61,7 @@ public: } private: - unsigned int m_uiIndex; + unsigned int m_uiIndex = 0; }; class CSASLMod : public CModule {