From 0851c3965879663c41cfe435d1b320ba68cf873a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 24 Dec 2012 15:03:40 +0000 Subject: fix for crash in RTF parser git-svn-id: http://svn.miranda-ng.org/main/trunk@2830 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/chat/message.cpp | 19 ++++------ plugins/TabSRMM/src/chat/window.cpp | 67 +++++++++++++++++------------------- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/plugins/TabSRMM/src/chat/message.cpp b/plugins/TabSRMM/src/chat/message.cpp index 71fbba7276..48ccf0ff64 100644 --- a/plugins/TabSRMM/src/chat/message.cpp +++ b/plugins/TabSRMM/src/chat/message.cpp @@ -84,13 +84,10 @@ static int ReadInteger(const char* p, int* result) TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si) { - char *p1; - int* pIndex; int i, iRemoveChars, cp = CP_ACP; char InsertThis[50]; BOOL bJustRemovedRTF = TRUE; BOOL bTextHasStarted = FALSE; - TCHAR *ptszResult; //, *d; int iUcMode = 0; if (!pszText) @@ -98,20 +95,20 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si) // create an index of colors in the module and map them to // corresponding colors in the RTF color table - pIndex = (int *)mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount); + mir_ptr pIndex((int*)mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount)); for (i=0; i < MM_FindModule(si->pszModule)->nColorCount ; i++) pIndex[i] = -1; CreateColorMap(pszText, pIndex, si); // scan the file for rtf commands and remove or parse them - p1 = strstr(pszText, "\\pard"); + char *p1 = strstr(pszText, "\\ltrpar"); if (p1 == NULL) { - mir_free(pIndex); - return FALSE; + if ((p1 = strstr(pszText, "\\pard")) == NULL) + return FALSE; + p1 += 5; } - - p1 += 5; + else p1 += 7; MoveMemory(pszText, p1, lstrlenA(p1) + 1); p1 = pszText; @@ -293,9 +290,7 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si) } else p1++; } - mir_free(pIndex); - ptszResult = mir_utf8decodeW(pszText); - return ptszResult; + return mir_utf8decodeW(pszText); } static DWORD CALLBACK Chat_Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp index 6d85d6244a..4f86fe2654 100644 --- a/plugins/TabSRMM/src/chat/window.cpp +++ b/plugins/TabSRMM/src/chat/window.cpp @@ -3153,44 +3153,41 @@ LABEL_SHOWWINDOW: ShowWindow(dat->pContainer->hwnd, SW_MINIMIZE); return FALSE; - case IDOK: { - char* pszRtf; - TCHAR* ptszText/*, *p1*/; - MODULEINFO* mi; - bool fSound = true; + case IDOK: + if (GetSendButtonState(hwndDlg) != PBS_DISABLED) { + MODULEINFO *mi = MM_FindModule(si->pszModule); - if (GetSendButtonState(hwndDlg) == PBS_DISABLED) - break; + mir_ptr pszRtf( Chat_Message_GetFromStream(hwndDlg, si)); + SM_AddCommand(si->ptszID, si->pszModule, pszRtf); + + mir_ptr ptszText( Chat_DoRtfToTags(pszRtf, si)); + if ((TCHAR*)ptszText == NULL) + break; + + DoTrimMessage(ptszText); - mi = MM_FindModule(si->pszModule); - - pszRtf = Chat_Message_GetFromStream(hwndDlg, si); - SM_AddCommand(si->ptszID, si->pszModule, pszRtf); - ptszText = Chat_DoRtfToTags(pszRtf, si); - DoTrimMessage(ptszText); - - if (mi && mi->bAckMsg) { - Utils::enableDlgControl(hwndDlg, IDC_CHAT_MESSAGE, FALSE); - SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, EM_SETREADONLY, TRUE, 0); - } else SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, WM_SETTEXT, 0, (LPARAM)_T("")); - - Utils::enableDlgControl(hwndDlg, IDOK, FALSE); - - if (ptszText[0] == '/' || si->iType == GCW_SERVER) - fSound = false; - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); - mi->idleTimeStamp = time(0); - mi->lastIdleCheck = 0; - SM_BroadcastMessage(si->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE); - if (dat && dat->pContainer) { - if (fSound && !nen_options.iNoSounds && !(dat->pContainer->dwFlags & CNT_NOSOUND)) - SkinPlaySound("ChatSent"); + if (mi && mi->bAckMsg) { + Utils::enableDlgControl(hwndDlg, IDC_CHAT_MESSAGE, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, EM_SETREADONLY, TRUE, 0); + } + else SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, WM_SETTEXT, 0, (LPARAM)_T("")); + + Utils::enableDlgControl(hwndDlg, IDOK, FALSE); + + bool fSound = true; + if (ptszText[0] == '/' || si->iType == GCW_SERVER) + fSound = false; + DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); + mi->idleTimeStamp = time(0); + mi->lastIdleCheck = 0; + SM_BroadcastMessage(si->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE); + if (dat && dat->pContainer) + if (fSound && !nen_options.iNoSounds && !(dat->pContainer->dwFlags & CNT_NOSOUND)) + SkinPlaySound("ChatSent"); + + SetFocus(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE)); } - mir_free(pszRtf); - mir_free(ptszText); - SetFocus(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE)); - } - break; + break; case IDC_SHOWNICKLIST: if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SHOWNICKLIST))) -- cgit v1.2.3