From 64671a888c73fd462e7872da81fcf02ef329adf7 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sat, 23 Nov 2019 22:01:31 +0100 Subject: [PATCH] Avoid passing null to strcat Static analysis indicated an issue, when line was being passed as 2nd argument to strcat: Null pointer passed as an argument to a 'nonnull' parameter Replace repeated strcat with creating a formatted string and use the opportunity to do a small format cleanup. --- src/shell/shell_cmds.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index 88cb072c..24273a96 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -104,17 +104,22 @@ static char* ExpandDot(char*args, char* buffer , size_t bufsize) { -bool DOS_Shell::CheckConfig(char* cmd_in,char*line) { +bool DOS_Shell::CheckConfig(char *cmd_in, char *line) { Section* test = control->GetSectionFromProperty(cmd_in); - if(!test) return false; - if(line && !line[0]) { + if (!test) + return false; + + if (line && !line[0]) { std::string val = test->GetPropValue(cmd_in); - if(val != NO_SUCH_PROPERTY) WriteOut("%s\n",val.c_str()); + if (val != NO_SUCH_PROPERTY) + WriteOut("%s\n", val.c_str()); return true; } - char newcom[1024]; newcom[0] = 0; strcpy(newcom,"z:\\config -set "); - strcat(newcom,test->GetName()); strcat(newcom," "); - strcat(newcom,cmd_in);strcat(newcom,line); + char newcom[1024]; + snprintf(newcom, sizeof(newcom), "z:\\config -set %s %s%s", + test->GetName(), + cmd_in, + line ? line : ""); DoCommand(newcom); return true; }