diff --git a/lib/addoninfo.cpp b/lib/addoninfo.cpp index cfe720b81..c96543f75 100644 --- a/lib/addoninfo.cpp +++ b/lib/addoninfo.cpp @@ -87,6 +87,11 @@ static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &j return ""; } + if (!obj.count("script") || !obj["script"].is()) + { + return "Loading " + fileName + " failed. script must be set to a string value."; + } + return addoninfo.getAddonInfo(obj["script"].get(), exename); } diff --git a/test/cli/test-other.py b/test/cli/test-other.py index 819f1d6a6..a183161fc 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -278,6 +278,22 @@ extern const char* f() 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')