summaryrefslogtreecommitdiff
path: root/plugins/FileAsMessage
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-05-15 06:14:17 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-05-15 06:14:17 +0000
commitcc2454c803eb6b96add654fbd99f616217056396 (patch)
tree31d12ba065f57c5c195cfd962243180ec9c01ff9 /plugins/FileAsMessage
parentb1571e501505713f1ee2aa8fed181268286d8a1d (diff)
fixed buffer overrun
git-svn-id: http://svn.miranda-ng.org/main/trunk@13600 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/FileAsMessage')
-rw-r--r--plugins/FileAsMessage/src/crc32.cpp10
-rw-r--r--plugins/FileAsMessage/src/dialog.cpp37
-rw-r--r--plugins/FileAsMessage/src/dialog.h18
-rw-r--r--plugins/FileAsMessage/src/main.cpp72
-rw-r--r--plugins/FileAsMessage/src/optionsdlg.cpp110
5 files changed, 115 insertions, 132 deletions
diff --git a/plugins/FileAsMessage/src/crc32.cpp b/plugins/FileAsMessage/src/crc32.cpp
index ab34393f8d..dc40c1a6fb 100644
--- a/plugins/FileAsMessage/src/crc32.cpp
+++ b/plugins/FileAsMessage/src/crc32.cpp
@@ -9,9 +9,9 @@ void InitCRC32()
{
UINT32 r = i;
for (int j = 0; j < 8; j++)
- if (r & 1)
+ if (r & 1)
r = (r >> 1) ^ CRCPoly;
- else
+ else
r >>= 1;
CRC32Table[i] = r;
}
@@ -21,11 +21,11 @@ const ulong INITCRC = -1L;
inline ulong UpdateCRC32(uchar val, ulong crc)
{
- return CRC32Table[(uchar)crc^val] ^ (crc>>8);
+ return CRC32Table[(uchar)crc^val] ^ (crc >> 8);
}
-ulong memcrc32(uchar *ptr, int size, ulong crc )
+ulong memcrc32(uchar *ptr, int size, ulong crc)
{
- while(size--) crc = UpdateCRC32(*ptr++, crc);
+ while (size--) crc = UpdateCRC32(*ptr++, crc);
return crc;
}
diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp
index 6f6ed39a23..718c34c9a9 100644
--- a/plugins/FileAsMessage/src/dialog.cpp
+++ b/plugins/FileAsMessage/src/dialog.cpp
@@ -66,24 +66,7 @@ static int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
{
MCONTACT hContact = PUGetContact(hWnd);
HWND hDlg = (HWND)PUGetPluginData(hWnd);
- /*
- if(hContact)
- {
- CLISTEVENT *lpcle;
- int indx = 0;
- for(;;)
- {
- if((lpcle = (CLISTEVENT*)CallService(MS_CLIST_GETEVENT, hContact, indx)) == NULL)
- break;
- if(mir_tstrcmp(lpcle->pszService, SERVICE_NAME "/FERecvFile") == 0)
- {
- lpcle->lParam = (LPARAM)hWnd;
- break;
- }
- indx++;
- }
- }
- */
+
switch (message) {
case WM_COMMAND:
{
@@ -423,11 +406,11 @@ void FILEECHO::sendReq()
return;
}
///!!!!!!!
- char *p = filename + strlen(filename);
+ char *p = filename + mir_strlen(filename);
while (p != filename && *p != '\\')
p--;
if (*p == '\\')
- strcpy(filename, p + 1);
+ mir_strcpy(filename, p + 1);
mir_snprintf(sendbuf, SIZEOF(sendbuf), Translate("Size: %d bytes"), fileSize);
SetDlgItemText(hDlg, IDC_FILESIZE, sendbuf);
@@ -446,9 +429,9 @@ void FILEECHO::incomeRequest(char *param)
char *p = strchr(param, '?');
if (p == NULL) return; *p++ = 0;
CallService(MS_FILE_GETRECEIVEDFILESFOLDER, hContact, (LPARAM)buf);
- strncat(buf, param, sizeof(buf));
+ mir_strncat(buf, param, SIZEOF(buf));
free(filename);
- filename = strdup(buf);
+ filename = mir_strdup(buf);
// p == &c
if (*p == 0) return; asBinary = (*p++) != '0';
if (*p == 0) return; codeSymb = *p++;
@@ -631,7 +614,7 @@ void FILEECHO::onSendTimer()
else
{
ptrA enc(mir_base64_encode(data, data_end - data));
- strncpy((char*)buffer, enc, chunkMaxLen * 2);
+ mir_strncpy((char*)buffer, enc, chunkMaxLen * 2);
}
char prefix[128];
@@ -865,9 +848,9 @@ int FILEECHO::sendCmd(int id, int cmd, char *szParam, char *szPrefix)
{
char *buf;
int retval;
- int buflen = (int)_tcslen(szServicePrefix) + (int)_tcslen(szParam) + 2;
+ int buflen = (int)mir_tstrlen(szServicePrefix) + (int)mir_tstrlen(szParam) + 2;
if (szPrefix != NULL)
- buflen += (int)_tcslen(szPrefix);
+ buflen += (int)mir_tstrlen(szPrefix);
buf = (char*)malloc(buflen);
if (szPrefix == NULL)
@@ -886,7 +869,7 @@ void CreateDirectoryTree(char *szDir)
DWORD dwAttributes;
char *pszLastBackslash, szTestDir[MAX_PATH];
- strncpy_s(szTestDir, szDir, _TRUNCATE);
+ mir_strncpy(szTestDir, szDir, _TRUNCATE);
if ((dwAttributes = GetFileAttributes(szTestDir)) != 0xffffffff && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
return;
pszLastBackslash = strrchr(szTestDir, '\\');
@@ -1186,7 +1169,7 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (size != -1)
mir_snprintf(str, SIZEOF(str), Translate("Size: %d bytes"), size);
else
- strncpy_s(str, Translate("Can't get a file size"), _TRUNCATE);
+ mir_strncpy(str, Translate("Can't get a file size"), _TRUNCATE);
SetDlgItemText(hDlg, IDC_FILESIZE, str);
break;
diff --git a/plugins/FileAsMessage/src/dialog.h b/plugins/FileAsMessage/src/dialog.h
index 962781b661..10f110bf37 100644
--- a/plugins/FileAsMessage/src/dialog.h
+++ b/plugins/FileAsMessage/src/dialog.h
@@ -2,12 +2,12 @@ extern HINSTANCE hInst;
int getMsgId(char *msg);
-INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
+INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
#ifdef _DEBUG
- #define CHECKPOINT
+#define CHECKPOINT
#else
- #define CHECKPOINT error
+#define CHECKPOINT error
#endif
#define TIMER_SEND 100
@@ -20,13 +20,13 @@ enum
CMD_REQ,
CMD_ACCEPT,
CMD_CANCEL,
-
+
CMD_NEXT,
-
+
CMD_DATA,
CMD_DACK,
CMD_END,
-
+
CMD_COUNT
};
@@ -95,13 +95,13 @@ public:
void setState(DWORD state);
void updateProgress();
void updateTitle();
-
+
void perform(char *str);
void cmdACCEPT();
void cmdDACK(char *data);
void sendReq();
int sendCmd(int id, int cmd, char *szParam, char *szPrefix = NULL);
-
+
void cmdDATA(char *data);
void cmdEND();
@@ -111,7 +111,7 @@ public:
void onSendTimer();
void onRecvTimer();
void incomeRequest(char *data);
-
+
};
void InitCRC32();
diff --git a/plugins/FileAsMessage/src/main.cpp b/plugins/FileAsMessage/src/main.cpp
index 4bc31d1a8f..fc3ce4b1c6 100644
--- a/plugins/FileAsMessage/src/main.cpp
+++ b/plugins/FileAsMessage/src/main.cpp
@@ -12,7 +12,7 @@ PLUGININFOEX pluginInfo =
__AUTHORWEB,
UNICODE_AWARE,
// {34B5A402-1B79-4246-B041-43D0B590AE2C}
- {0x34b5a402, 0x1b79, 0x4246, {0xb0, 0x41, 0x43, 0xd0, 0xb5, 0x90, 0xae, 0x2c}}
+ { 0x34b5a402, 0x1b79, 0x4246, { 0xb0, 0x41, 0x43, 0xd0, 0xb5, 0x90, 0xae, 0x2c } }
};
HANDLE hFileList;
@@ -25,7 +25,7 @@ HANDLE hHookDbSettingChange, hHookContactAdded, hHookSkinIconsChanged;
HICON hIcons[5];
-static IconItem iconList[] =
+static IconItem iconList[] =
{
{ LPGEN("Play"), "FePlay", IDI_PLAY },
{ LPGEN("Pause"), "FePause", IDI_PAUSE },
@@ -34,28 +34,28 @@ static IconItem iconList[] =
{ LPGEN("Main"), "FeMain", IDI_SMALLICON },
};
-int iIconId[5] = {3,2,4,1,0};
+int iIconId[5] = { 3, 2, 4, 1, 0 };
//
// wParam - Section name
// lParam - Icon ID
//
-int OnSkinIconsChanged(WPARAM wParam,LPARAM lParam)
+int OnSkinIconsChanged(WPARAM wParam, LPARAM lParam)
{
- for(int indx = 0; indx < SIZEOF(hIcons); indx++)
- hIcons[indx] = Skin_GetIconByHandle( iconList[indx].hIcolib );
+ for (int indx = 0; indx < SIZEOF(hIcons); indx++)
+ hIcons[indx] = Skin_GetIconByHandle(iconList[indx].hIcolib);
- WindowList_Broadcast(hFileList, WM_FE_SKINCHANGE, 0,0);
+ WindowList_Broadcast(hFileList, WM_FE_SKINCHANGE, 0, 0);
return 0;
}
int OnSettingChanged(WPARAM hContact, LPARAM lParam)
{
- DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
HWND hwnd = WindowList_Find(hFileList, hContact);
- PostMessage(hwnd, WM_FE_STATUSCHANGE, 0,0);
+ PostMessage(hwnd, WM_FE_STATUSCHANGE, 0, 0);
return 0;
}
@@ -64,7 +64,7 @@ INT_PTR OnRecvFile(WPARAM wParam, LPARAM lParam)
CLISTEVENT *clev = (CLISTEVENT*)lParam;
HWND hwnd = WindowList_Find(hFileList, clev->hContact);
- if(IsWindow(hwnd))
+ if (IsWindow(hwnd))
{
ShowWindow(hwnd, SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
@@ -73,17 +73,17 @@ INT_PTR OnRecvFile(WPARAM wParam, LPARAM lParam)
/*
else
{
- if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
- FILEECHO *fe = new FILEECHO((HANDLE)clev->hContact);
- fe->inSend = FALSE;
- hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)DialogProc, (LPARAM)fe);
- if(hwnd == NULL)
- {
- delete fe;
- return 0;
- }
- //SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE);
- ShowWindow(hwnd, SW_SHOWNORMAL);
+ if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
+ FILEECHO *fe = new FILEECHO((HANDLE)clev->hContact);
+ fe->inSend = FALSE;
+ hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)DialogProc, (LPARAM)fe);
+ if(hwnd == NULL)
+ {
+ delete fe;
+ return 0;
+ }
+ //SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE);
+ ShowWindow(hwnd, SW_SHOWNORMAL);
}
*/
return 1;
@@ -92,18 +92,18 @@ INT_PTR OnRecvFile(WPARAM wParam, LPARAM lParam)
INT_PTR OnSendFile(WPARAM wParam, LPARAM lParam)
{
HWND hwnd = WindowList_Find(hFileList, wParam);
- if(IsWindow(hwnd))
+ if (IsWindow(hwnd))
{
SetForegroundWindow(hwnd);
SetFocus(hwnd);
}
else
{
- if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
+ if (hwnd != 0) WindowList_Remove(hFileList, hwnd);
FILEECHO *fe = new FILEECHO(wParam);
fe->inSend = TRUE;
hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc, (LPARAM)fe);
- if(hwnd == NULL)
+ if (hwnd == NULL)
{
delete fe;
return 0;
@@ -117,25 +117,25 @@ INT_PTR OnSendFile(WPARAM wParam, LPARAM lParam)
INT_PTR OnRecvMessage(WPARAM wParam, LPARAM lParam)
{
CCSDATA *pccsd = (CCSDATA *)lParam;
- PROTORECVEVENT *ppre = ( PROTORECVEVENT * )pccsd->lParam;
+ PROTORECVEVENT *ppre = (PROTORECVEVENT *)pccsd->lParam;
- if(strncmp(ppre->szMessage, szServicePrefix, strlen(szServicePrefix)))
+ if (strncmp(ppre->szMessage, szServicePrefix, mir_strlen(szServicePrefix)))
return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
HWND hwnd = WindowList_Find(hFileList, pccsd->hContact);
- if(!IsWindow(hwnd))
+ if (!IsWindow(hwnd))
{
- if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
+ if (hwnd != 0) WindowList_Remove(hFileList, hwnd);
FILEECHO *fe = new FILEECHO(pccsd->hContact);
fe->inSend = FALSE;
hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc, (LPARAM)fe);
- if(hwnd == NULL)
+ if (hwnd == NULL)
{
delete fe;
return 0;
}
}
- char *msg = strdup(ppre->szMessage + strlen(szServicePrefix));
+ char *msg = mir_strdup(ppre->szMessage + mir_strlen(szServicePrefix));
PostMessage(hwnd, WM_FE_MESSAGE, (WPARAM)pccsd->hContact, (LPARAM)msg);
return 0;
@@ -148,7 +148,7 @@ int OnOptInitialise(WPARAM wParam, LPARAM lParam)
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
odp.ptszTitle = _T(SERVICE_TITLE);
odp.ptszGroup = LPGENT("Events");
- odp.flags = ODPF_BOLDGROUPS|ODPF_TCHAR;
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
odp.pfnDlgProc = OptionsDlgProc;
Options_AddPage(wParam, &odp);
return 0;
@@ -167,10 +167,10 @@ extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD dwVersi
// Startup initializing
//
-static int OnModulesLoaded(WPARAM wparam,LPARAM lparam)
+static int OnModulesLoaded(WPARAM wparam, LPARAM lparam)
{
- for(int indx = 0; indx < SIZEOF(hIcons); indx++)
- hIcons[indx] = Skin_GetIconByHandle( iconList[indx].hIcolib );
+ for (int indx = 0; indx < SIZEOF(hIcons); indx++)
+ hIcons[indx] = Skin_GetIconByHandle(iconList[indx].hIcolib);
hHookSkinIconsChanged = HookEvent(ME_SKIN2_ICONSCHANGED, OnSkinIconsChanged);
@@ -202,7 +202,7 @@ extern "C" __declspec(dllexport) int Load(void)
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
pd.szName = SERVICE_NAME;
pd.type = PROTOTYPE_FILTER;
- CallService(MS_PROTO_REGISTERMODULE, 0, ( LPARAM ) &pd);
+ CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
HookEvent(ME_OPT_INITIALISE, OnOptInitialise);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
@@ -219,7 +219,7 @@ extern "C" __declspec(dllexport) int Load(void)
extern "C" __declspec(dllexport) int Unload(void)
{
WindowList_Destroy(hFileList);
- if(hHookSkinIconsChanged != NULL)
+ if (hHookSkinIconsChanged != NULL)
UnhookEvent(hHookSkinIconsChanged);
UnhookEvent(hHookDbSettingChange);
UnhookEvent(hHookContactAdded);
diff --git a/plugins/FileAsMessage/src/optionsdlg.cpp b/plugins/FileAsMessage/src/optionsdlg.cpp
index 679cade77e..df20bc5ade 100644
--- a/plugins/FileAsMessage/src/optionsdlg.cpp
+++ b/plugins/FileAsMessage/src/optionsdlg.cpp
@@ -2,10 +2,10 @@
DWORD settingDefault[] =
{
- RGB(64,255,64),
- RGB(255,255,64),
- RGB(128,128,128),
- RGB(192,192,192),
+ RGB(64, 255, 64),
+ RGB(255, 255, 64),
+ RGB(128, 128, 128),
+ RGB(192, 192, 192),
6000,
5000
@@ -35,76 +35,76 @@ int settingId[] =
// this handles the options page
// verwaltet die Optionsseite
//
-INT_PTR CALLBACK OptionsDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
+INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch( uMsg )
+ switch (uMsg)
{
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
-
- for(int indx = 0; indx < SIZEOF(settingId); indx++)
- if(settingId[indx] > 0)
- SendDlgItemMessage(hwndDlg, settingId[indx], CPM_SETCOLOUR, 0, db_get_dw(NULL, SERVICE_NAME, settingName[indx], settingDefault[indx]));
- else
- SetDlgItemInt(hwndDlg, -settingId[indx], db_get_dw(NULL, SERVICE_NAME, settingName[indx], settingDefault[indx]), FALSE);
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
- CheckDlgButton(hwndDlg, IDC_ALPHANUM, db_get_dw(NULL, SERVICE_NAME, "base64", 1) ? BST_CHECKED : BST_UNCHECKED);
+ for (int indx = 0; indx < SIZEOF(settingId); indx++)
+ if (settingId[indx] > 0)
+ SendDlgItemMessage(hwndDlg, settingId[indx], CPM_SETCOLOUR, 0, db_get_dw(NULL, SERVICE_NAME, settingName[indx], settingDefault[indx]));
+ else
+ SetDlgItemInt(hwndDlg, -settingId[indx], db_get_dw(NULL, SERVICE_NAME, settingName[indx], settingDefault[indx]), FALSE);
- return TRUE;
+ CheckDlgButton(hwndDlg, IDC_ALPHANUM, db_get_dw(NULL, SERVICE_NAME, "base64", 1) ? BST_CHECKED : BST_UNCHECKED);
- }
- case WM_COMMAND:
+ return TRUE;
+
+ }
+ case WM_COMMAND:
+ {
+ if (//MAKEWPARAM(IDC_AUTO, BN_CLICKED) != wParam ||
+ MAKEWPARAM(IDC_ALPHANUM, BN_CLICKED) != wParam)
{
- if(//MAKEWPARAM(IDC_AUTO, BN_CLICKED) != wParam ||
- MAKEWPARAM(IDC_ALPHANUM, BN_CLICKED) != wParam)
- {
- for(int indx = 0; indx < SIZEOF(settingId); indx++)
+ for (int indx = 0; indx < SIZEOF(settingId); indx++)
+ {
+ if (LOWORD(wParam) == abs(settingId[indx]))
{
- if(LOWORD(wParam) == abs(settingId[indx]))
+ if (settingId[indx] > 0)
+ {
+ if (HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
+ }
+ else
{
- if(settingId[indx] > 0)
- {
- if(HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
- }
- else
- {
- if(HIWORD(wParam) != EN_CHANGE) return FALSE;
- if((HWND)lParam != GetFocus()) return FALSE;
- }
+ if (HIWORD(wParam) != EN_CHANGE) return FALSE;
+ if ((HWND)lParam != GetFocus()) return FALSE;
}
}
}
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0,0);
- break;
}
- case WM_DESTROY:
- return FALSE;
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ }
+ case WM_DESTROY:
+ return FALSE;
- case WM_NOTIFY:
+ case WM_NOTIFY:
+ {
+ if ((((NMHDR*)lParam)->idFrom == 0) && (((LPNMHDR)lParam)->code == PSN_APPLY))
{
- if((((NMHDR*)lParam)->idFrom == 0) && (((LPNMHDR)lParam)->code == PSN_APPLY))
+ int value;
+ BOOL succ;
+
+ for (int indx = 0; indx < SIZEOF(settingId); indx++)
{
- int value;
- BOOL succ;
-
- for(int indx = 0; indx < SIZEOF(settingId); indx++)
+ if (settingId[indx] > 0)
+ value = SendDlgItemMessage(hwndDlg, settingId[indx], CPM_GETCOLOUR, 0, 0);
+ else
{
- if(settingId[indx] > 0)
- value = SendDlgItemMessage(hwndDlg, settingId[indx], CPM_GETCOLOUR, 0, 0);
- else
- {
- value = GetDlgItemInt(hwndDlg, -settingId[indx], &succ, FALSE);
- if(!succ) value = settingDefault[indx];
- }
- db_set_dw(NULL,SERVICE_NAME,settingName[indx], value);
+ value = GetDlgItemInt(hwndDlg, -settingId[indx], &succ, FALSE);
+ if (!succ) value = settingDefault[indx];
}
- db_set_dw(NULL,SERVICE_NAME, "base64", (IsDlgButtonChecked(hwndDlg, IDC_ALPHANUM) == BST_CHECKED)?1:0);
-
- return TRUE;
+ db_set_dw(NULL, SERVICE_NAME, settingName[indx], value);
}
- break;
+ db_set_dw(NULL, SERVICE_NAME, "base64", (IsDlgButtonChecked(hwndDlg, IDC_ALPHANUM) == BST_CHECKED) ? 1 : 0);
+
+ return TRUE;
}
+ break;
+ }
}