@@ -318,10 +318,10 @@ namespace {
318318 };
319319}
320320
321- static std::string cmdFileName (std::string f)
321+ std::string CppCheck:: cmdFileName (std::string f)
322322{
323323 f = Path::toNativeSeparators (std::move (f));
324- if (f.find ( ' ' ) != std::string::npos)
324+ if (f.find_first_of ( " \t ;$<>|&` \n " ) != std::string::npos)
325325 return " \" " + f + " \" " ;
326326 return f;
327327}
@@ -456,11 +456,11 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
456456 std::string pythonExe;
457457
458458 if (!addonInfo.executable .empty ())
459- pythonExe = addonInfo.executable ;
459+ pythonExe = CppCheck::cmdFileName ( addonInfo.executable ) ;
460460 else if (!addonInfo.python .empty ())
461- pythonExe = cmdFileName (addonInfo.python );
461+ pythonExe = CppCheck:: cmdFileName (addonInfo.python );
462462 else if (!defaultPythonExe.empty ())
463- pythonExe = cmdFileName (defaultPythonExe);
463+ pythonExe = CppCheck:: cmdFileName (defaultPythonExe);
464464 else {
465465 // store in static variable so we only look this up once - TODO: do not cache globally
466466 static const std::string detectedPythonExe = detectPython (executeCommand);
@@ -471,13 +471,13 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
471471
472472 std::string args;
473473 if (addonInfo.executable .empty ())
474- args = cmdFileName (addonInfo.runScript ) + " " + cmdFileName (addonInfo.scriptFile );
474+ args = CppCheck:: cmdFileName (addonInfo.runScript ) + " " + CppCheck:: cmdFileName (addonInfo.scriptFile );
475475 args += std::string (args.empty () ? " " : " " ) + " --cli" + addonInfo.args ;
476476 if (!premiumArgs.empty () && !addonInfo.executable .empty ())
477477 args += " " + premiumArgs;
478478
479479 const bool is_file_list = (file.find (FILELIST ) != std::string::npos);
480- const std::string fileArg = (is_file_list ? " --file-list " : " " ) + cmdFileName (file);
480+ const std::string fileArg = (is_file_list ? " --file-list " : " " ) + CppCheck:: cmdFileName (file);
481481 args += fileArg;
482482
483483 std::string result;
@@ -672,7 +672,7 @@ static std::string getClangFlags(const Settings& setting, Standards::Language la
672672 flags += getDefinesFlags (setting.userDefines );
673673
674674 for (const std::string &i: setting.userIncludes )
675- flags += " --include " + cmdFileName (i) + " " ;
675+ flags += " --include " + CppCheck:: cmdFileName (i) + " " ;
676676
677677 return flags;
678678}
0 commit comments