From cb8ff5c1221d3c820142cf2333face1ab8f03c93 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 7 Dec 2023 17:34:17 +0300 Subject: fixes #3679 (StopSpam/StopSpamMod: Jabber message query overflow) --- plugins/StopSpamMod/src/init.cpp | 20 +++++++-------- plugins/StopSpamMod/src/options.cpp | 48 +++++++++++++++++------------------ plugins/StopSpamMod/src/stopspam.cpp | 24 +++++++++--------- plugins/StopSpamMod/src/utilities.cpp | 28 ++++++++++---------- 4 files changed, 59 insertions(+), 61 deletions(-) (limited to 'plugins/StopSpamMod/src') diff --git a/plugins/StopSpamMod/src/init.cpp b/plugins/StopSpamMod/src/init.cpp index c989aae78f..91e926469d 100644 --- a/plugins/StopSpamMod/src/init.cpp +++ b/plugins/StopSpamMod/src/init.cpp @@ -38,23 +38,23 @@ BOOL gbCaseInsensitive = 0; BOOL gbRegexMatch = 0; BOOL gbInvisDisable = 0; BOOL gbIgnoreURL = 1; -BOOL gbLogToFile=0; -BOOL gbAutoAuth=0; -BOOL gbAutoAddToServerList=0; -BOOL gbAutoReqAuth=1; +BOOL gbLogToFile = 0; +BOOL gbAutoAuth = 0; +BOOL gbAutoAddToServerList = 0; +BOOL gbAutoReqAuth = 1; BOOL gbMathExpression = 0; HANDLE hStopSpamLogDirH = nullptr; wstring gbSpammersGroup = L"Spammers"; -wstring gbAutoAuthGroup = L"NotSpammers"; +wstring gbAutoAuthGroup = L"NotSpammers"; wstring gbQuestion; wstring gbAnswer; wstring gbCongratulation; std::wstring gbAuthRepl; extern const wchar_t *defQuestion, *defCongrats, *defAuthReply; -extern int RemoveTmp(WPARAM,LPARAM); +extern int RemoveTmp(WPARAM, LPARAM); ///////////////////////////////////////////////////////////////////////////////////////// // returns plugin's extended information @@ -69,7 +69,7 @@ PLUGININFOEX pluginInfoEx = { __AUTHORWEB, UNICODE_AWARE, // {94CED94C-A94A-4BB1-ACBD-5CC6EBB689D4} - {0x94ced94c, 0xa94a, 0x4bb1, {0xac, 0xbd, 0x5c, 0xc6, 0xeb, 0xb6, 0x89, 0xd4}} + { 0x94ced94c, 0xa94a, 0x4bb1, { 0xac, 0xbd, 0x5c, 0xc6, 0xeb, 0xb6, 0x89, 0xd4 } } }; CMPlugin::CMPlugin() : @@ -78,7 +78,7 @@ CMPlugin::CMPlugin() : ///////////////////////////////////////////////////////////////////////////////////////// -extern wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, wstring errorValue); +extern wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const *szModule, char const *szSetting, wstring errorValue); void InitVars() { @@ -116,9 +116,9 @@ static int OnSystemModulesLoaded(WPARAM, LPARAM) gbVarsServiceExist = TRUE; InitVars(); - if(gbDelExcluded) + if (gbDelExcluded) mir_forkthread(&CleanThread); - + // Folders plugin support hStopSpamLogDirH = FoldersRegisterCustomPathW(LPGEN("StopSpam"), LPGEN("StopSpam Logs"), FOLDER_LOGS); return 0; diff --git a/plugins/StopSpamMod/src/options.cpp b/plugins/StopSpamMod/src/options.cpp index c610a4aa24..1958598f63 100644 --- a/plugins/StopSpamMod/src/options.cpp +++ b/plugins/StopSpamMod/src/options.cpp @@ -25,13 +25,16 @@ const wchar_t *defAuthReply = LPGENW("StopSpam: send a message and reply to an a class COptMainDlg : public CDlgBase { + CCtrlCheck chk_INFTALKPROT, chk_ADDPERMANENT, chk_HANDLEAUTHREQ, chk_HIDECONTACTS, chk_IGNORESPAMMERS, chk_LOGSPAMTOFILE; + CCtrlData ctrl_DESCRIPTION; + CCtrlSpin edit_MAXQUESTCOUNT; + public: COptMainDlg() : CDlgBase(g_plugin, IDD_MAIN), chk_INFTALKPROT(this, ID_INFTALKPROT), chk_ADDPERMANENT(this, ID_ADDPERMANENT), chk_HANDLEAUTHREQ(this, ID_HANDLEAUTHREQ), chk_HIDECONTACTS(this, ID_HIDECONTACTS), chk_IGNORESPAMMERS(this, ID_IGNORESPAMMERS), chk_LOGSPAMTOFILE(this, ID_LOGSPAMTOFILE), ctrl_DESCRIPTION(this, ID_DESCRIPTION), edit_MAXQUESTCOUNT(this, ID_MAXQUESTCOUNT) - { - } + {} bool OnInitDialog() override { @@ -57,15 +60,13 @@ public: g_plugin.setByte("LogSpamToFile", gbLogToFile = chk_LOGSPAMTOFILE.GetState()); return true; } - -private: - CCtrlCheck chk_INFTALKPROT, chk_ADDPERMANENT, chk_HANDLEAUTHREQ, chk_HIDECONTACTS, chk_IGNORESPAMMERS, chk_LOGSPAMTOFILE; - CCtrlData ctrl_DESCRIPTION; - CCtrlSpin edit_MAXQUESTCOUNT; }; class COptMessagesDlg : public CDlgBase { + CCtrlEdit edit_QUESTION, edit_ANSWER, edit_CONGRATULATION, edit_AUTHREPL; + CCtrlButton btn_RESTOREDEFAULTS, btn_VARS; + public: COptMessagesDlg() : CDlgBase(g_plugin, IDD_MESSAGES), edit_QUESTION(this, ID_QUESTION), edit_ANSWER(this, ID_ANSWER), edit_CONGRATULATION(this, ID_CONGRATULATION), edit_AUTHREPL(this, ID_AUTHREPL), @@ -102,25 +103,24 @@ public: return true; } - void onClick_RESTOREDEFAULTS(CCtrlButton*) + void onClick_RESTOREDEFAULTS(CCtrlButton *) { edit_QUESTION.SetText(TranslateW(defQuestion)); edit_ANSWER.SetText(L"nospam"); edit_AUTHREPL.SetText(TranslateW(defAuthReply)); edit_CONGRATULATION.SetText(TranslateW(defCongrats)); } - void onClick_VARS(CCtrlButton*) + void onClick_VARS(CCtrlButton *) { variables_showhelp(m_hwnd, WM_COMMAND, VHF_FULLDLG | VHF_SETLASTSUBJECT, nullptr, nullptr); } -private: - CCtrlEdit edit_QUESTION, edit_ANSWER, edit_CONGRATULATION, edit_AUTHREPL; - CCtrlButton btn_RESTOREDEFAULTS, btn_VARS; - }; class COptProtoDlg : public CDlgBase { + CCtrlListBox list_USEDPROTO, list_ALLPROTO; + CCtrlButton btn_ADD, btn_REMOVE, btn_ADDALL, btn_REMOVEALL; + public: COptProtoDlg() : CDlgBase(g_plugin, IDD_PROTO), list_USEDPROTO(this, ID_USEDPROTO), list_ALLPROTO(this, ID_ALLPROTO), @@ -131,7 +131,7 @@ public: btn_ADDALL.OnClick = Callback(this, &COptProtoDlg::onClick_ADDALL); btn_REMOVEALL.OnClick = Callback(this, &COptProtoDlg::onClick_REMOVEALL); } - + bool OnInitDialog() override { for (auto &pa : Accounts()) { @@ -141,10 +141,9 @@ public: } return true; } - + bool OnApply() override { - LRESULT count = list_USEDPROTO.GetCount(); std::ostringstream out; for (int i = 0; i < count; ++i) { @@ -156,19 +155,21 @@ public: return true; } - void onClick_ADD(CCtrlButton*) + void onClick_ADD(CCtrlButton *) { list_USEDPROTO.AddString(list_ALLPROTO.GetItemText(list_ALLPROTO.GetCurSel())); list_ALLPROTO.DeleteString(list_ALLPROTO.GetCurSel()); this->NotifyChange(); } - void onClick_REMOVE(CCtrlButton*) + + void onClick_REMOVE(CCtrlButton *) { list_ALLPROTO.AddString(list_USEDPROTO.GetItemText(list_USEDPROTO.GetCurSel())); list_USEDPROTO.DeleteString(list_USEDPROTO.GetCurSel()); this->NotifyChange(); } - void onClick_ADDALL(CCtrlButton*) + + void onClick_ADDALL(CCtrlButton *) { for (;;) { int count = list_ALLPROTO.GetCount(); @@ -179,7 +180,8 @@ public: } this->NotifyChange(); } - void onClick_REMOVEALL(CCtrlButton*) + + void onClick_REMOVEALL(CCtrlButton *) { for (;;) { int count = list_USEDPROTO.GetCount(); @@ -190,10 +192,6 @@ public: } this->NotifyChange(); } -private: - CCtrlListBox list_USEDPROTO, list_ALLPROTO; - CCtrlButton btn_ADD, btn_REMOVE, btn_ADDALL, btn_REMOVEALL; - }; class COptAdvancedDlg : public CDlgBase @@ -282,7 +280,7 @@ public: return true; } - void onClick_MATH_DETAILS(CCtrlButton*) + void onClick_MATH_DETAILS(CCtrlButton *) { MessageBox(m_hwnd, TranslateT("If math expression is turned on, you can use following expression in message text:\nXX+XX-X/X*X\neach X will be replaced by one random number and answer will be expression result.\nMessage must contain only one expression without spaces."), TranslateT("Info"), MB_OK); } diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index ae9e4bcb9e..ec80f97f3b 100644 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -70,7 +70,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) return 0; // if event is in protocol that is not despammed - DBEVENTINFO * dbei = (DBEVENTINFO*)l; + DBEVENTINFO *dbei = (DBEVENTINFO *)l; if (!ProtoInList(dbei->szModule)) return 0; // ...let the event go its way @@ -87,18 +87,18 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) // we want block not only messages, i seen many types other eventtype flood if (dbei->flags & DBEF_READ) return 0; // ...let the event go its way - + // mark contact which we trying to contact for exclude from check if ((dbei->flags & DBEF_SENT) && !Contact::OnList(hContact) && (!gbMaxQuestCount || g_plugin.getDword(hContact, "QuestionCount") < gbMaxQuestCount) && gbExclude) { g_plugin.setByte(hContact, "Excluded", 1); return 0; } - + // if message is from known or marked Answered contact if (Contact::OnList(hContact)) return 0; // ...let the event go its way - + // if message is corrupted or empty it cannot be an answer. if (!dbei->cbBlob || !dbei->pBlob) // reject processing of the event @@ -106,9 +106,9 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring message; if (dbei->flags & DBEF_UTF) - message = ptrW(mir_utf8decodeW((char*)dbei->pBlob)); + message = ptrW(mir_utf8decodeW((char *)dbei->pBlob)); else - message = _A2T((char*)(dbei->pBlob)); + message = _A2T((char *)(dbei->pBlob)); // if message contains right answer... @@ -147,7 +147,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) answered = boost::regex_search(msg.begin(), msg.end(), expr); } } - + if (answered) { // unhide contact Contact::Hide(hContact, false); @@ -166,7 +166,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring prot = DBGetContactSettingStringPAN(NULL, dbei->szModule, "AM_BaseProto", L""); // for notICQ protocols or disable auto auth. request if ((Stricmp(L"ICQ", prot.c_str())) || (!gbAutoReqAuth)) { - char * buf = mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); + char *buf = mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf); mir_free(buf); } @@ -180,7 +180,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) Clist_SetGroup(hContact, gbAutoAuthGroup.c_str()); Contact::PutOnList(hContact); } - + // auto auth. request with send congratulation if (gbAutoReqAuth) ProtoChainSend(hContact, PSS_AUTHREQUEST, 0, (LPARAM)variables_parse(gbCongratulation, hContact).c_str()); @@ -199,7 +199,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring q; if (gbInfTalkProtection) q += L"StopSpam automatic message:\r\n"; - + if (gbMathExpression) { //parse math expression in question wstring tmp_question = gbQuestion; std::list args; @@ -219,7 +219,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) actions.push_back(gbQuestion[p1]); ++p1; } - + int math_answer = 0; math_answer = args.front(); args.pop_front(); @@ -282,7 +282,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) int OnDbContactSettingChanged(WPARAM w, LPARAM l) { MCONTACT hContact = (MCONTACT)w; - DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l; + auto *cws = (DBCONTACTWRITESETTING *)l; // if CList/NotOnList is being deleted then remove answeredSetting if (strcmp(cws->szModule, "CList")) diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index da3e855812..b7aac4ddb4 100644 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -17,18 +17,18 @@ #include "stdafx.h" -wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, wstring errorValue) +wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const *szModule, char const *szSetting, wstring errorValue) { DBVARIANT dbv; - if (db_get_ws(hContact, szModule, szSetting, &dbv)) + if (db_get_ws(hContact, szModule, szSetting, &dbv)) return errorValue; - + errorValue = dbv.pwszVal; db_free(&dbv); return errorValue; } -std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szModule, char const * szSetting, std::string errorValue) +std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const *szModule, char const *szSetting, std::string errorValue) { DBVARIANT dbv; if (db_get_s(hContact, szModule, szSetting, &dbv)) @@ -39,11 +39,11 @@ std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szMod return errorValue; } -wstring& GetDlgItemString(HWND hwnd, int id) +wstring &GetDlgItemString(HWND hwnd, int id) { HWND h = GetDlgItem(hwnd, id); int len = GetWindowTextLength(h); - wchar_t * buf = new wchar_t[len + 1]; + wchar_t *buf = new wchar_t[len + 1]; GetWindowText(h, buf, len + 1); static wstring s; s = buf; @@ -65,7 +65,7 @@ bool ProtoInList(const char *szProto) return std::string::npos != GetProtoList().find(std::string(szProto) + "\r\n"); } -void DeleteCListGroupsByName(wchar_t* szGroupName) +void DeleteCListGroupsByName(wchar_t *szGroupName) { uint8_t ConfirmDelete = Clist::ConfirmDelete; if (ConfirmDelete) @@ -94,7 +94,7 @@ wstring variables_parse(wstring const &tstrFormat, MCONTACT hContact) fi.szFormat.w = wcsdup(tstrFormat.c_str()); fi.hContact = hContact; fi.flags = FIF_UNICODE; - wchar_t *tszParsed = (wchar_t*)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); + wchar_t *tszParsed = (wchar_t *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); free(fi.szFormat.w); if (tszParsed) { @@ -194,7 +194,7 @@ void LogSpamToFile(MCONTACT hContact, wstring message) // Name, UID and Protocol Log line LogProtocol = DBGetContactSettingStringPAN(hContact, "Protocol", "p", L""); - LogContactName = (wchar_t*)Clist_GetContactDisplayName(hContact); + LogContactName = (wchar_t *)Clist_GetContactDisplayName(hContact); LogContactId = (LogProtocol == L"") ? L"" : GetContactUid(hContact, LogProtocol); // Name, UID and Protocol Log line @@ -215,7 +215,7 @@ mir_cs clean_mutex; void __cdecl CleanProtocolExclThread(void *param) { - const char *szProto = (const char*)param; + const char *szProto = (const char *)param; while (true) { int status = Proto_GetStatus(szProto); @@ -242,7 +242,7 @@ void __cdecl CleanProtocolExclThread(void *param) mir_free(param); } -void __cdecl CleanThread(void*) +void __cdecl CleanThread(void *) { std::list protocols; for (auto &pa : Accounts()) @@ -262,7 +262,7 @@ void HistoryLog(MCONTACT hContact, char *data, int event_type, int flags) Event.flags = flags | DBEF_UTF; Event.timestamp = (uint32_t)time(0); Event.cbBlob = (uint32_t)mir_strlen(data) + 1; - Event.pBlob = (uint8_t*)_strdup(data); + Event.pBlob = (uint8_t *)_strdup(data); db_event_add(hContact, &Event); } @@ -277,7 +277,7 @@ void HistoryLogFunc(MCONTACT hContact, std::string message) msg.append("Protocol: ").append(Proto_GetBaseAccountName(hContact)).append(" Contact: "); msg.append(toUTF8(Clist_GetContactDisplayName(hContact))).append(" ID: "); msg.append(toUTF8(GetContactUid(hContact, toUTF16(Proto_GetBaseAccountName(hContact))))); - HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ); + HistoryLog(NULL, (char *)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ); } } @@ -301,7 +301,7 @@ std::string get_random_num(int length) std::string chars("123456789"); std::string data; boost::random_device rng; - boost::variate_generator> gen(rng, boost::uniform_int<>(0, (int)chars.length() - 1)); + boost::variate_generator> gen(rng, boost::uniform_int<>(0, (int)chars.length() - 1)); for (int i = 0; i < length; ++i) data += chars[gen()]; return data; -- cgit v1.2.3