From 303e6b483aff4126701ca375dd085e9ae1d18b43 Mon Sep 17 00:00:00 2001 From: Rozhuk Ivan Date: Sat, 13 Dec 2014 08:01:55 +0000 Subject: multiple buf size fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@11361 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AutoShutdown/src/utils.cpp | 11 ++++++----- plugins/AvatarHistory/src/AvatarDlg.cpp | 2 +- plugins/AvatarHistory/src/AvatarHistory.cpp | 12 +++++++----- plugins/FileAsMessage/src/dialog.cpp | 21 ++++++++++++--------- plugins/Utils/mir_fonts.cpp | 11 ++++++----- plugins/YAMN/src/browser/badconnect.cpp | 6 +++--- 6 files changed, 35 insertions(+), 28 deletions(-) (limited to 'plugins') diff --git a/plugins/AutoShutdown/src/utils.cpp b/plugins/AutoShutdown/src/utils.cpp index 7eeab7d78f..4335dd7566 100644 --- a/plugins/AutoShutdown/src/utils.cpp +++ b/plugins/AutoShutdown/src/utils.cpp @@ -260,12 +260,13 @@ int FontService_RegisterColor(const char *pszDbModule,const char *pszDbName,cons int FontService_GetColor(const TCHAR *pszSection,const TCHAR *pszDescription,COLORREF *pclr) { ColourIDT cid; + memset(&cid, 0, sizeof(cid)); - cid.cbSize=sizeof(cid); - mir_tstrncpy(cid.group,pszSection,sizeof(cid.group)); /* buffer safe */ - mir_tstrncpy(cid.name,pszDescription,sizeof(cid.name)); /* buffer safe */ - *pclr=(COLORREF)CallService(MS_COLOUR_GETT,(WPARAM)&cid,0); - return (int)*pclr==-1; + cid.cbSize = sizeof(cid); + _tcsncpy_s(cid.group, pszSection, _TRUNCATE); + _tcsncpy_s(cid.name, pszDescription, _TRUNCATE); + *pclr = (COLORREF)CallService(MS_COLOUR_GETT, (WPARAM)&cid, 0); + return (int)*pclr == -1; } /************************* Skin ***********************************/ diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index 491d3d34be..64ac70749d 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -554,7 +554,7 @@ int ShowSaveDialog(HWND hwnd, TCHAR* fn, MCONTACT hContact) ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; - mir_tstrncpy(file, _tcsrchr(fn, '\\')+1, sizeof(file)); + _tcsncpy_s(file, (_tcsrchr(fn, '\\') + 1), _TRUNCATE); ofn.lpstrFile = file; TCHAR *displayName = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME,hContact,GCDNF_TCHAR); diff --git a/plugins/AvatarHistory/src/AvatarHistory.cpp b/plugins/AvatarHistory/src/AvatarHistory.cpp index cd3489212b..1f98aa149a 100644 --- a/plugins/AvatarHistory/src/AvatarHistory.cpp +++ b/plugins/AvatarHistory/src/AvatarHistory.cpp @@ -75,9 +75,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) static INT_PTR GetCachedAvatar(WPARAM wParam, LPARAM lParam) { TCHAR hash[128]; - mir_tstrncpy(hash, (TCHAR *) lParam, sizeof(hash)); - ConvertToFilename(hash, sizeof(hash)); - return (INT_PTR) GetCachedAvatar((char *) wParam, hash); + + _tcsncpy_s(hash, (TCHAR*)lParam, _TRUNCATE); + ConvertToFilename(hash, SIZEOF(hash)); + return (INT_PTR)GetCachedAvatar((char*)wParam, hash); } static INT_PTR IsEnabled(WPARAM wParam, LPARAM lParam) @@ -169,8 +170,9 @@ static int AvatarChanged(WPARAM hContact, LPARAM lParam) else { // See if we already have the avatar TCHAR hash[128]; - mir_tstrncpy(hash, avatar->hash, sizeof(hash)); - ConvertToFilename(hash, sizeof(hash)); + + _tcsncpy_s(hash, avatar->hash, _TRUNCATE); + ConvertToFilename(hash, SIZEOF(hash)); TCHAR *file = GetCachedAvatar(proto, hash); diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp index 9cc63c3929..2b144d6048 100644 --- a/plugins/FileAsMessage/src/dialog.cpp +++ b/plugins/FileAsMessage/src/dialog.cpp @@ -884,16 +884,19 @@ int FILEECHO::sendCmd(int id, int cmd, char *szParam, char *szPrefix) void CreateDirectoryTree(char *szDir) { DWORD dwAttributes; - char *pszLastBackslash,szTestDir[MAX_PATH]; - - mir_tstrncpy(szTestDir,szDir,sizeof(szTestDir)); - if((dwAttributes=GetFileAttributes(szTestDir))!=0xffffffff - && dwAttributes&FILE_ATTRIBUTE_DIRECTORY) return; - pszLastBackslash=strrchr(szTestDir,'\\'); - if(pszLastBackslash==NULL) {GetCurrentDirectory(MAX_PATH,szDir); return;} - *pszLastBackslash='\0'; + char *pszLastBackslash, szTestDir[MAX_PATH]; + + strncpy_s(szTestDir, szDir, _TRUNCATE); + if((dwAttributes = GetFileAttributes(szTestDir)) != 0xffffffff && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + return; + pszLastBackslash = strrchr(szTestDir, '\\'); + if (pszLastBackslash == NULL) { + GetCurrentDirectory(MAX_PATH, szDir); + return; + } + *pszLastBackslash = 0; CreateDirectoryTree(szTestDir); - CreateDirectory(szTestDir,NULL); + CreateDirectory(szTestDir, NULL); } LRESULT CALLBACK ProgressWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/plugins/Utils/mir_fonts.cpp b/plugins/Utils/mir_fonts.cpp index 237eb040f7..768ac12363 100644 --- a/plugins/Utils/mir_fonts.cpp +++ b/plugins/Utils/mir_fonts.cpp @@ -60,10 +60,11 @@ int FontService_RegisterColor(const char *pszDbModule,const char *pszDbName,cons int FontService_GetColor(const TCHAR *pszSection,const TCHAR *pszDescription,COLORREF *pclr) { ColourIDT cid; + memset(&cid, 0, sizeof(cid)); - cid.cbSize=sizeof(cid); - mir_tstrncpy(cid.group,pszSection,sizeof(cid.group)); /* buffer safe */ - mir_tstrncpy(cid.name,pszDescription,sizeof(cid.name)); /* buffer safe */ - *pclr=(COLORREF)CallService(MS_COLOUR_GETT,(WPARAM)&cid,0); - return (int)*pclr==-1; + cid.cbSize = sizeof(cid); + _tcsncpy_s(cid.group, pszSection, _TRUNCATE); + _tcsncpy_s(cid.name, pszDescription, _TRUNCATE); + *pclr = (COLORREF)CallService(MS_COLOUR_GETT, (WPARAM)&cid, 0); + return (int)*pclr == -1; } diff --git a/plugins/YAMN/src/browser/badconnect.cpp b/plugins/YAMN/src/browser/badconnect.cpp index eeccc75553..6339ebaba5 100644 --- a/plugins/YAMN/src/browser/badconnect.cpp +++ b/plugins/YAMN/src/browser/badconnect.cpp @@ -125,7 +125,7 @@ INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARA if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr != NULL) { Message1W = ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - mir_tstrncpy(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); + _tcsncpy_s(BadConnectPopup.lptzText, Message1W, _TRUNCATE); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } @@ -133,7 +133,7 @@ INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARA { Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - mir_tstrncpy(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); + _tcsncpy_s(BadConnectPopup.lptzText, Message1W, _TRUNCATE); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } @@ -141,7 +141,7 @@ INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARA { Message1W=TranslateT("Unknown error"); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - mir_tstrncpy(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); + _tcsncpy_s(BadConnectPopup.lptzText, Message1W, _TRUNCATE); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } -- cgit v1.2.3