Skip to content

fix #13968: Addon execution fails for some paths with spaces on Windows #7632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,10 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
joinedArgs += arg;
}

const std::string cmd = exe + " " + joinedArgs + " " + redirect;
std::string cmd = exe + " " + joinedArgs + " " + redirect;

#ifdef _WIN32
cmd = "\"" + cmd + "\"";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spontanously this looks wrong to me. If cmd is:

"C:\Program Files\Cppcheck Premium\premiumaddon.exe" --cli foo.c.dump

then here it is changed to:

""C:\Program Files\Cppcheck Premium\premiumaddon.exe" --cli foo.c.dump"

so if the initial "" are removed then that is:

C:\Program Files\Cppcheck Premium\premiumaddon.exe" --cli foo.c.dump"

Is this intended behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what situation would the "" be removed?

Copy link
Owner

@danmar danmar Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. I believe that "" means nothing in the command processor?

I assume that a command ""C:\Program Files\Cppcheck Premium\premiumaddon.exe" --cli foo.c.dump" would fail if I execute it in a windows command terminal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows command line seems to parse quotations differently: https://stackoverflow.com/a/6378038

FILE* p = _popen(cmd.c_str(), "r");
#else
FILE *p = popen(cmd.c_str(), "r");
Expand Down
24 changes: 24 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ def test_execute_addon_failure_json_notexist(tmpdir):
assert stderr == "{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon.json' - exitcode is {} [internalError]\n\n^\n".format(test_file, ec)


@pytest.mark.skipif(sys.platform != "win32", reason="Windows specific issue")
def test_execute_addon_path_with_spaces(tmpdir):
addon_json = os.path.join(tmpdir, 'addon.json')
addon_executable = os.path.join(tmpdir, 'A Folder', 'addon.exe')
with open(addon_json, 'wt') as f:
f.write(json.dumps({'executable': addon_executable }))

test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
pass

args = [
'--addon={}'.format(addon_json),
test_file,
'--verbose',
'--debug'
]

_, _, stderr = cppcheck(args)

# Make sure the full command is used
assert 'The system cannot find the path specified. [internalError]' in stderr
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand this test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, the error is similar to the one in the ticket, i.e. the part before the whitespace is interpreted as a command, and the rest of the path it's argument(s).



def test_execute_addon_failure_json_ctu_notexist(tmpdir):
# specify non-existent python executable so execution of addon fails
addon_json = os.path.join(tmpdir, 'addon.json')
Expand Down
Loading