@@ -326,10 +326,10 @@ namespace {
326326 };
327327}
328328
329- static std::string cmdFileName (std::string f)
329+ std::string CppCheck:: cmdFileName (std::string f)
330330{
331331 f = Path::toNativeSeparators (std::move (f));
332- if (f.find ( ' ' ) != std::string::npos)
332+ if (f.find_first_of ( " \t ;$<>|&` \n " ) != std::string::npos)
333333 return " \" " + f + " \" " ;
334334 return f;
335335}
@@ -464,11 +464,11 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
464464 std::string pythonExe;
465465
466466 if (!addonInfo.executable .empty ())
467- pythonExe = addonInfo.executable ;
467+ pythonExe = CppCheck::cmdFileName ( addonInfo.executable ) ;
468468 else if (!addonInfo.python .empty ())
469- pythonExe = cmdFileName (addonInfo.python );
469+ pythonExe = CppCheck:: cmdFileName (addonInfo.python );
470470 else if (!defaultPythonExe.empty ())
471- pythonExe = cmdFileName (defaultPythonExe);
471+ pythonExe = CppCheck:: cmdFileName (defaultPythonExe);
472472 else {
473473 // store in static variable so we only look this up once - TODO: do not cache globally
474474 static const std::string detectedPythonExe = detectPython (executeCommand);
@@ -479,13 +479,13 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
479479
480480 std::string args;
481481 if (addonInfo.executable .empty ())
482- args = cmdFileName (addonInfo.runScript ) + " " + cmdFileName (addonInfo.scriptFile );
482+ args = CppCheck:: cmdFileName (addonInfo.runScript ) + " " + CppCheck:: cmdFileName (addonInfo.scriptFile );
483483 args += std::string (args.empty () ? " " : " " ) + " --cli" + addonInfo.args ;
484484 if (!premiumArgs.empty () && !addonInfo.executable .empty ())
485485 args += " " + premiumArgs;
486486
487487 const bool is_file_list = (file.find (FILELIST ) != std::string::npos);
488- const std::string fileArg = (is_file_list ? " --file-list " : " " ) + cmdFileName (file);
488+ const std::string fileArg = (is_file_list ? " --file-list " : " " ) + CppCheck:: cmdFileName (file);
489489 args += fileArg;
490490
491491 std::string result;
@@ -680,7 +680,7 @@ static std::string getClangFlags(const Settings& setting, Standards::Language la
680680 flags += getDefinesFlags (setting.userDefines );
681681
682682 for (const std::string &i: setting.userIncludes )
683- flags += " --include " + cmdFileName (i) + " " ;
683+ flags += " --include " + CppCheck:: cmdFileName (i) + " " ;
684684
685685 return flags;
686686}
0 commit comments