From c16625bfdc49c39ea6c159a70a87b95bbdc7a6c9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 20 Mar 2015 22:11:15 +0000 Subject: fix for a possible memory corruption git-svn-id: http://svn.miranda-ng.org/main/trunk@12458 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/NewXstatusNotify/src/indsnd.cpp | 2 +- plugins/NewXstatusNotify/src/main.cpp | 50 ++++++++++++++------------------- 2 files changed, 22 insertions(+), 30 deletions(-) (limited to 'plugins') diff --git a/plugins/NewXstatusNotify/src/indsnd.cpp b/plugins/NewXstatusNotify/src/indsnd.cpp index a7765b0e39..50e35d5245 100644 --- a/plugins/NewXstatusNotify/src/indsnd.cpp +++ b/plugins/NewXstatusNotify/src/indsnd.cpp @@ -63,7 +63,7 @@ TCHAR *SelectSound(HWND hwndDlg, TCHAR *buff, size_t bufflen) OPENFILENAME ofn = { 0 }; HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST); - ListView_GetItemText(hList, ListView_GetNextItem(hList, -1, LVNI_SELECTED), 1, buff, bufflen); + ListView_GetItemText(hList, ListView_GetNextItem(hList, -1, LVNI_SELECTED), 1, buff, (DWORD)bufflen); if (!mir_tstrcmp(buff, TranslateT(DEFAULT_SOUND))) buff = NULL; diff --git a/plugins/NewXstatusNotify/src/main.cpp b/plugins/NewXstatusNotify/src/main.cpp index 46f123a3cd..3cab47ec08 100644 --- a/plugins/NewXstatusNotify/src/main.cpp +++ b/plugins/NewXstatusNotify/src/main.cpp @@ -180,54 +180,49 @@ static int CompareStatusMsg(STATUSMSGINFO *smi, DBCONTACTWRITESETTING *cws_new, return ret; } -TCHAR *GetStr(STATUSMSGINFO *n, const TCHAR *tmplt) +TCHAR* GetStr(STATUSMSGINFO *n, const TCHAR *tmplt) { if (n == NULL || tmplt == NULL || tmplt[0] == _T('\0')) return NULL; - TCHAR *str = (TCHAR *)mir_alloc(2048 * sizeof(TCHAR)); - str[0] = _T('\0'); + CMString res; size_t len = mir_tstrlen(tmplt); - TCHAR tmp[1024]; for (size_t i = 0; i < len; i++) { - tmp[0] = _T('\0'); - if (tmplt[i] == _T('%')) { i++; switch (tmplt[i]) { case 'n': if (n->compare == COMPARE_DEL || mir_tstrcmp(n->newstatusmsg, TranslateT("")) == 0) - mir_tstrncpy(tmp, TranslateT(""), SIZEOF(tmp)); + res.Append(TranslateT("")); else - mir_tstrncpy(tmp, ptrT(AddCR(n->newstatusmsg)), SIZEOF(tmp)); + res.Append(ptrT(AddCR(n->newstatusmsg))); break; case 'o': if (n->oldstatusmsg == NULL || n->oldstatusmsg[0] == _T('\0') || _tcscmp(n->oldstatusmsg, TranslateT("")) == 0) - mir_tstrncpy(tmp, TranslateT(""), SIZEOF(tmp)); + res.Append(TranslateT("")); else - mir_tstrncpy(tmp, ptrT(AddCR(n->oldstatusmsg)), SIZEOF(tmp)); + res.Append(ptrT(AddCR(n->oldstatusmsg))); break; case 'c': if (n->hContact == NULL) - mir_tstrncpy(tmp, TranslateT("Contact"), SIZEOF(tmp)); + res.Append(TranslateT("Contact")); else - mir_tstrncpy(tmp, (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)n->hContact, GCDNF_TCHAR), SIZEOF(tmp)); + res.Append((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)n->hContact, GCDNF_TCHAR)); break; case 's': if (n->hContact == NULL) - mir_tstrncpy(tmp, TranslateT(""), SIZEOF(tmp)); + res.Append(TranslateT("")); else - - mir_tstrncpy(tmp, StatusList[Index(db_get_w(n->hContact, n->proto, "Status", ID_STATUS_ONLINE))].lpzStandardText, SIZEOF(tmp)); + res.Append(StatusList[Index(db_get_w(n->hContact, n->proto, "Status", ID_STATUS_ONLINE))].lpzStandardText); break; default: i--; - tmp[0] = tmplt[i], tmp[1] = _T('\0'); + res.AppendChar(tmplt[i]); break; } } @@ -235,30 +230,27 @@ TCHAR *GetStr(STATUSMSGINFO *n, const TCHAR *tmplt) i++; switch (tmplt[i]) { case 'n': - tmp[0] = _T('\r'), tmp[1] = _T('\n'), tmp[2] = _T('\0'); + res.AppendChar('\r'); + res.AppendChar('\n'); break; case 't': - tmp[0] = _T('\t'), tmp[1] = _T('\0'); + res.AppendChar('\t'); break; default: i--; - tmp[0] = tmplt[i], tmp[1] = _T('\0'); + res.AppendChar(tmplt[i]); break; } } - else tmp[0] = tmplt[i], tmp[1] = _T('\0'); + else res.AppendChar(tmplt[i]); + } - if (tmp[0] != _T('\0')) { - if (mir_tstrlen(tmp) + mir_tstrlen(str) < 2044) - mir_tstrcat(str, tmp); - else { - mir_tstrcat(str, _T("...")); - break; - } - } + if (res.GetLength() > 2044) { + res.Truncate(2044); + res.Append(_T("...")); } - return str; + return mir_tstrndup(res, res.GetLength()); } bool SkipHiddenContact(MCONTACT hContact) -- cgit v1.2.3