From ec112925e1c1419182451cc2f0f6e985d9ddb1de Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 28 May 2015 15:44:00 +0000 Subject: unsafe strncat removed git-svn-id: http://svn.miranda-ng.org/main/trunk@13875 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CmdLine/MimCmd/src/commands.cpp | 56 ++++++++++++++------------------- plugins/CmdLine/MimCmd/src/common.h | 1 + 2 files changed, 25 insertions(+), 32 deletions(-) (limited to 'plugins/CmdLine/MimCmd/src') diff --git a/plugins/CmdLine/MimCmd/src/commands.cpp b/plugins/CmdLine/MimCmd/src/commands.cpp index 2cbdfe7430..bdccae6709 100644 --- a/plugins/CmdLine/MimCmd/src/commands.cpp +++ b/plugins/CmdLine/MimCmd/src/commands.cpp @@ -119,55 +119,47 @@ PCommand GetCommand(char *command) void HandleHelpCommand(PCommand helpCommand, char *argv[], int argc, PReply reply) { - const int size = REPLY_SIZE; - if (argc >= 3) - { + CMStringA szReply; + + if (argc >= 3) { PCommand command = GetCommand(argv[2]); - if (command) - { + if (command) { reply->code = MIMRES_SUCCESS; - STRNCPY(reply->message, Translate(command->help), size); + szReply.Append(Translate(command->help)); } - else{ + else { reply->code = MIMRES_NOTFOUND; - mir_snprintf(reply->message, size, Translate("No help for '%s'."), argv[2]); - reply->message[size -1 ] = 0; + szReply.AppendFormat(Translate("No help for '%s'."), argv[2]); } } - else{ + else { reply->code = MIMRES_SUCCESS; - STRNCPY(reply->message, Translate("Available commands: "), size); + szReply.Append(Translate("Available commands: ")); - for (int i = 0; i < cKnownCommands - 1; i++) - { - mir_strncat(reply->message, knownCommands[i].command, SIZEOF(reply->message) - mir_strlen(reply->message)); - mir_strncat(reply->message, ", ", SIZEOF(reply->message) - mir_strlen(reply->message)); + for (int i = 0; i < cKnownCommands - 1; i++) { + szReply.Append(knownCommands[i].command); + szReply.Append(", "); } - mir_strncat(reply->message, knownCommands[cKnownCommands - 1].command, SIZEOF(reply->message) - mir_strlen(reply->message)); - mir_strncat(reply->message, ".", SIZEOF(reply->message) - mir_strlen(reply->message)); + szReply.Append(knownCommands[cKnownCommands-1].command); + szReply.AppendChar('.'); } + strncpy_s(reply->message, szReply, _TRUNCATE); } PReply ParseCommand(char *argv[], int argc) { PCommand command = GetCommand(argv[1]); - if (command) - { - PReply reply = &sdCmdLine->reply; - if (command->ID == MIMCMD_HELP) - { - HandleHelpCommand(command, argv, argc, reply); - } - else{ - ProcessConsoleCommand(command, argv, argc, reply); - } - - return reply; - } - else{ + if (!command) return NULL; - } + + PReply reply = &sdCmdLine->reply; + if (command->ID == MIMCMD_HELP) + HandleHelpCommand(command, argv, argc, reply); + else + ProcessConsoleCommand(command, argv, argc, reply); + + return reply; } void FillSharedDataStruct(PCommand command, char *arguments[], int count) diff --git a/plugins/CmdLine/MimCmd/src/common.h b/plugins/CmdLine/MimCmd/src/common.h index 2b6057ec9c..675276cf09 100644 --- a/plugins/CmdLine/MimCmd/src/common.h +++ b/plugins/CmdLine/MimCmd/src/common.h @@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "..\..\src\mimcmd_ipc.h" #include "version.h" -- cgit v1.2.3