From 7666c2ce26dd9a6e2fb129dea4d2fad9bcdbe591 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 28 May 2015 15:43:44 +0000 Subject: unsafe strncat removed git-svn-id: http://svn.miranda-ng.org/main/trunk@13874 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/YahooGroups/src/commonheaders.h | 1 + plugins/YahooGroups/src/list.cpp | 4 +-- plugins/YahooGroups/src/list.h | 4 +-- plugins/YahooGroups/src/services.cpp | 43 +++++++++++---------------------- 4 files changed, 19 insertions(+), 33 deletions(-) (limited to 'plugins/YahooGroups/src') diff --git a/plugins/YahooGroups/src/commonheaders.h b/plugins/YahooGroups/src/commonheaders.h index 61d51f6236..db316c3b18 100644 --- a/plugins/YahooGroups/src/commonheaders.h +++ b/plugins/YahooGroups/src/commonheaders.h @@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include "version.h" diff --git a/plugins/YahooGroups/src/list.cpp b/plugins/YahooGroups/src/list.cpp index 364f468926..abfde10670 100644 --- a/plugins/YahooGroups/src/list.cpp +++ b/plugins/YahooGroups/src/list.cpp @@ -86,12 +86,12 @@ int CGroupsList::Count() return count; } -int CGroupsList::Contains(char *group) +int CGroupsList::Contains(const char *group) { return (Index(group) >= 0); } -int CGroupsList::Index(char *group) +int CGroupsList::Index(const char *group) { int i; for (i = 0; i < count; i++) diff --git a/plugins/YahooGroups/src/list.h b/plugins/YahooGroups/src/list.h index ef34699e7c..3414d8fdec 100644 --- a/plugins/YahooGroups/src/list.h +++ b/plugins/YahooGroups/src/list.h @@ -42,8 +42,8 @@ class CGroupsList int Count(); - int Contains(char *group); - int Index(char *group); + int Contains(const char *group); + int Index(const char *group); char *operator [](int index); }; diff --git a/plugins/YahooGroups/src/services.cpp b/plugins/YahooGroups/src/services.cpp index a5a0b01cfd..f13cd473ff 100644 --- a/plugins/YahooGroups/src/services.cpp +++ b/plugins/YahooGroups/src/services.cpp @@ -87,7 +87,7 @@ int GetNextGroupIndex() return index - 1; } -void AddNewGroup(char *newGroup) +void AddNewGroup(const char *newGroup) { int index = GetNextGroupIndex(); @@ -119,44 +119,29 @@ void CreateGroup(char *group) { char *p = group; char *sub = group; - char buffer[1024] = {0}; - + + CMStringA buf; while ((p = strchr(sub, '\\'))) { *p = 0; - if (mir_strlen(buffer) > 0) - { - mir_strncat(buffer, "\\", SIZEOF(buffer) - mir_strlen(buffer)); - mir_strncat(buffer, sub, SIZEOF(buffer) - mir_strlen(buffer)); - } - else{ - strncpy_s(buffer, sub, _TRUNCATE); - } + if (!buf.IsEmpty()) + buf.AppendChar('\\'); + buf.Append(sub); - if (!availableGroups.Contains(buffer)) - { - AddNewGroup(buffer); - } + if (!availableGroups.Contains(buf)) + AddNewGroup(buf); *p++ = '\\'; sub = p; } - if (sub) - { - if (mir_strlen(buffer) > 0) - { - mir_strncat(buffer, "\\", SIZEOF(buffer) - mir_strlen(buffer)); - mir_strncat(buffer, sub, SIZEOF(buffer) - mir_strlen(buffer)); - } - else{ - strncpy_s(buffer, sub, _TRUNCATE); - } + if (sub) { + if (!buf.IsEmpty()) + buf.AppendChar('\\'); + buf.Append(sub); - if (!availableGroups.Contains(buffer)) - { - AddNewGroup(buffer); - } + if (!availableGroups.Contains(buf)) + AddNewGroup(buf); } } -- cgit v1.2.3