diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-07-29 22:17:00 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-07-29 22:17:00 +0300 |
commit | 5d6a4181191ec5eb92f2596fe6099f4009ec12ff (patch) | |
tree | 376a62e8f3c8e7a1300b2bd3a07124c25dc6d5d1 /src/main.cpp | |
parent | 4b918c8f61749cfc0cfc9a8abd0c3b06af042faf (diff) |
fixed memorry corruption's
improoved autoexchange
Diffstat (limited to 'src/main.cpp')
-rwxr-xr-x | src/main.cpp | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/src/main.cpp b/src/main.cpp index 3857f38..0c212d4 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1218,16 +1218,17 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, { wstring path; { //data sanity checks - TCHAR *tmp = new TCHAR [5]; + TCHAR *tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5); GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); if(_tcslen(tmp) < 3) { - mir_free(tmp); + mir_free(tmp); tmp = NULL; MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK); break; } - mir_free(tmp); - tmp = new TCHAR [5]; + if(tmp) + mir_free(tmp); + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*6); GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); int length = _ttoi(tmp); mir_free(tmp); @@ -1236,39 +1237,39 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, MessageBox(0, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK); break; } - tmp = new TCHAR [12]; - GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*12); + GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 11); if(_tcslen(tmp) != 10 && tmp[0] != '0') { MessageBox(0, TranslateT("Invalid date"), TranslateT("Error"), MB_OK); - delete [] tmp; + mir_free(tmp); break; } - delete [] tmp; - tmp = new TCHAR [128]; - GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); + mir_free(tmp); + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128); + GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 127); if(_tcslen(tmp) < 5) { MessageBox(0, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK); - delete [] tmp; + mir_free(tmp); break; } else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')'))) { MessageBox(0, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK); - delete [] tmp; + mir_free(tmp); break; } - delete [] tmp; - tmp = new TCHAR [128]; + mir_free(tmp); + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128); GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.')))) { MessageBox(0, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK); - delete [] tmp; + mir_free(tmp); break; } - delete [] tmp; + mir_free(tmp); } { //generating key file TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); @@ -1284,11 +1285,11 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, break; } f<<"Key-Type: "; - tmp = new TCHAR [5]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5); GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); tmp2 = mir_t2a(tmp); - delete [] tmp; - char *subkeytype = new char [6]; + mir_free(tmp); + char *subkeytype = (char*)mir_alloc(6); if(strstr(tmp2, "RSA")) strcpy(subkeytype, "RSA"); else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support @@ -1297,10 +1298,10 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, mir_free(tmp2); f<<"\n"; f<<"Key-Length: "; - tmp = new TCHAR [5]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5); GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); int length = _ttoi(tmp); - delete [] tmp; + mir_free(tmp); f<<length; f<<"\n"; f<<"Subkey-Length: "; @@ -1308,9 +1309,9 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, f<<"\n"; f<<"Subkey-Type: "; f<<subkeytype; - delete [] subkeytype; + mir_free(subkeytype); f<<"\n"; - tmp = new TCHAR [64]; //i hope this is enough for password + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*64); //i hope this is enough for password GetDlgItemText(hwndDlg, IDC_KEY_PASSWD, tmp, 64); if(tmp[0]) { @@ -1320,16 +1321,16 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, f<<"\n"; mir_free(tmp2); } - delete [] tmp; + mir_free(tmp); f<<"Name-Real: "; - tmp = new TCHAR [128]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128); GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); tmp2 = mir_strdup(toUTF8(tmp).c_str()); f<<tmp2; mir_free(tmp2); - delete [] tmp; + mir_free(tmp); f<<"\n"; - tmp = new TCHAR [512]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*512); GetDlgItemText(hwndDlg, IDC_KEY_COMMENT, tmp, 512); if(tmp[0]) { @@ -1339,22 +1340,22 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, f<<"\n"; } mir_free(tmp2); - delete [] tmp; + mir_free(tmp); f<<"Name-Email: "; - tmp = new TCHAR [128]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128); GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); tmp2 = mir_strdup(toUTF8(tmp).c_str()); f<<tmp2; mir_free(tmp2); - delete [] tmp; + mir_free(tmp); f<<"\n"; f<<"Expire-Date: "; - tmp = new TCHAR [12]; + tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*12); GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); tmp2 = mir_strdup(toUTF8(tmp).c_str()); f<<tmp2; mir_free(tmp2); - delete [] tmp; + mir_free(tmp); f<<"\n"; f.close(); } @@ -2023,14 +2024,25 @@ void InitCheck() mir_free(path); } extern bool bAutoExchange; - if(bAutoExchange && (ServiceExists("ICQ"PS_ICQ_ADDCAPABILITY))) //work only for one icq instance + if(bAutoExchange) { + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); ICQ_CUSTOMCAP cap; cap.cbSize = sizeof(ICQ_CUSTOMCAP); cap.hIcon = 0; strcpy(cap.name, "GPG Key AutoExchange"); strcpy(cap.caps, "GPG AutoExchange"); - CallService("ICQ"PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap); + + for(int i = 0; i < count; i++) + { + char svc[64]; + strcpy(svc, accounts[i]->szProtoName); + strcat(svc, PS_ICQ_ADDCAPABILITY); + if(ServiceExists(svc)) + CallService(svc, 0, (LPARAM)&cap); + } } } |