@@ -326,9 +326,9 @@ namespace {
326326 };
327327}
328328
329- std::string CppCheck::cmdFileName (std::string f)
329+ /* * throw if filename contains characters that potentially has a special meaning for the shell */
330+ static void checkCmdFileName (const std::string& f)
330331{
331- // do not allow characters that potentially has a special meaning for the shell
332332 const auto badpos = f.find_first_of (" \t\n\r ;$<>|&`" );
333333 if (badpos != std::string::npos) {
334334 std::string c;
@@ -342,6 +342,11 @@ std::string CppCheck::cmdFileName(std::string f)
342342 c += f[badpos];
343343 throw std::runtime_error (" Cppcheck does not allow character " + c + " in filename " + f);
344344 }
345+ }
346+
347+ std::string CppCheck::cmdFileName (std::string f)
348+ {
349+ checkCmdFileName (f);
345350 f = Path::toNativeSeparators (std::move (f));
346351 if (f.find (' ' ) != std::string::npos)
347352 return " \" " + f + " \" " ;
@@ -477,9 +482,11 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
477482
478483 std::string pythonExe;
479484
480- if (!addonInfo.executable .empty ())
481- pythonExe = CppCheck::cmdFileName (addonInfo.executable );
482- else if (!addonInfo.python .empty ())
485+ if (!addonInfo.executable .empty ()) {
486+ // no quoting here, executeCommand quotes the executable if needed
487+ checkCmdFileName (addonInfo.executable );
488+ pythonExe = addonInfo.executable ;
489+ } else if (!addonInfo.python .empty ())
483490 pythonExe = CppCheck::cmdFileName (addonInfo.python );
484491 else if (!defaultPythonExe.empty ())
485492 pythonExe = CppCheck::cmdFileName (defaultPythonExe);
0 commit comments