From d2ffea815c2763595d6ef9b96ced20d45944135f Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 18 Aug 2012 03:00:02 +0300 Subject: possible memmory corruption fixes --- src/init.cpp | 2 +- src/main.cpp | 8 ++++---- src/messages.cpp | 58 +++++++++++++++++++++++++++++++------------------------ src/options.cpp | 8 ++++---- src/utilities.cpp | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 90030b0..52e4ede 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -231,7 +231,7 @@ static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) if(bJabberAPI && bIsMiranda09) HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); - HookEvent(ME_PROTO_ACK, onProtoAck); //filetransfer unimplemented now + HookEvent(ME_PROTO_ACK, onProtoAck); HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); diff --git a/src/main.cpp b/src/main.cpp index 0c212d4..e28114c 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2261,7 +2261,7 @@ void ImportKey() s2 = output.find("<", s); else if(s2 > output.find("<", s)) s2 = output.find("<", s); - tmp = new char [output.substr(s,s2-s-1).length()+1]; + tmp = (char*)mir_alloc(sizeof(char)*(output.substr(s,s2-s-1).length()+1)); strcpy(tmp, output.substr(s,s2-s-1).c_str()); mir_utf8decode(tmp, 0); DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp); @@ -2273,14 +2273,14 @@ void ImportKey() s2++; if(output[s] == ')') { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2,s-s2).length()+1)); strcpy(tmp, output.substr(s2,s-s2).c_str()); mir_utf8decode(tmp, 0); DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp); mir_free(tmp); s+=3; s2 = output.find(">", s); - tmp = new char [output.substr(s,s2-s).length()+1]; + tmp = (char*) mir_alloc(sizeof(char)*(output.substr(s,s2-s).length()+1)); strcpy(tmp, output.substr(s,s2-s).c_str()); mir_utf8decode(tmp, 0); DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp); @@ -2288,7 +2288,7 @@ void ImportKey() } else { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2,s-s2).length()+1)); strcpy(tmp, output.substr(s2,s-s2).c_str()); mir_utf8decode(tmp, 0); DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); diff --git a/src/messages.cpp b/src/messages.cpp index ba9a36c..3cb0af1 100755 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -25,7 +25,7 @@ int returnNoError(HANDLE hContact); std::list sent_msgs; -int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) +void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) { DWORD dbflags = DBEF_UTF; { //check for gpg related data @@ -69,7 +69,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D { HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } } { @@ -169,13 +169,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } //TODO: check gpg output for errors _terminate = false; @@ -233,13 +233,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } //TODO: check gpg output for errors } @@ -258,7 +258,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { @@ -292,7 +292,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); mir_free(tmp); - return 0; + return; } } } @@ -329,7 +329,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); mir_free(tmp); - return 0; + return; } else { @@ -344,12 +344,12 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); mir_free(msg); - return 0; + return; } char *tmp = mir_strdup(toUTF8(str).c_str()); HistoryLog(hContact, db_event(tmp, timestamp, 0, dbflags)); mir_free(tmp); - return 0; + return; } } } @@ -361,13 +361,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D { HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); - return 0; + return; } HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } int RecvMsgSvc(WPARAM w, LPARAM l) @@ -621,7 +621,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) return returnNoError(ccs->hContact); } -int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) +void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { wstring str; bool isansi = false; @@ -668,7 +668,8 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, DBEF_SENT)); hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); mir_free(msg); - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + return; } if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself cmd += _T("--comment \"\" --no-version "); @@ -714,12 +715,14 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) params.hProcess = NULL; debuglog<