Skip to content
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

lib/addoninfo.cpp: When loading a JSON addon, test 'script' key. #5797

Merged
merged 1 commit into from
Dec 25, 2023
Merged
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
5 changes: 5 additions & 0 deletions lib/addoninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &j
return "";
}

if (!obj.count("script") || !obj["script"].is<std::string>())
{
return "Loading " + fileName + " failed. script must be set to a string value.";
}

return addoninfo.getAddonInfo(obj["script"].get<std::string>(), exename);
}

Expand Down
16 changes: 16 additions & 0 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ def test_addon_threadsafety(tmpdir):
assert stderr == '{}:4:12: warning: strerror is MT-unsafe [threadsafety-unsafe-call]\n'.format(test_file)


def test_addon_invalidjson(tmpdir):
addon_file = os.path.join(tmpdir, 'invalid.json')
with open(addon_file, 'wt') as f:
f.write("""
{
"Script": "addons/something.py"
}
""")

args = ['--addon={}'.format(addon_file), '--enable=all', 'nonexistent.cpp']

exitcode, stdout, stderr = cppcheck(args)
assert exitcode != 0
assert stdout == 'Loading {} failed. script must be set to a string value.\n'.format(addon_file)


def test_addon_naming(tmpdir):
# the addon does nothing without a config
addon_file = os.path.join(tmpdir, 'naming1.json')
Expand Down
Loading