From 931ef0e2193c2768e0481b4b9fce3a4da56f5590 Mon Sep 17 00:00:00 2001 From: stswidwinski Date: Mon, 18 Sep 2023 23:23:12 +0800 Subject: [PATCH 1/2] Add an if statement to make sure that we do not execute something which does not have a config specified. --- helper/pluginutils/loader/init.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helper/pluginutils/loader/init.go b/helper/pluginutils/loader/init.go index d43636cf02d..3fb262df23c 100644 --- a/helper/pluginutils/loader/init.go +++ b/helper/pluginutils/loader/init.go @@ -264,7 +264,11 @@ func (l *PluginLoader) fingerprintPlugins(plugins []os.FileInfo, configs map[str fingerprinted := make(map[PluginID]*pluginInfo, len(plugins)) for _, p := range plugins { name := cleanPluginExecutable(p.Name()) - c := configs[name] + c, config_does_exist := configs[name] + if !config_does_exist { + l.logger.Error("failed to load config for plugin. Is it specified in the config?", "plugin", name) + continue + } info, err := l.fingerprintPlugin(p, c) if err != nil { l.logger.Error("failed to fingerprint plugin", "plugin", name, "error", err) From 99cc2c138d3cc5f424e1dc495cd49d65954bc1d5 Mon Sep 17 00:00:00 2001 From: stswidwinski Date: Mon, 18 Sep 2023 23:25:50 +0800 Subject: [PATCH 2/2] Extend existing tests to make sure that files which are not listed as extensions are not executed. --- helper/pluginutils/loader/loader_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/helper/pluginutils/loader/loader_test.go b/helper/pluginutils/loader/loader_test.go index 939ee7b7104..1f8a50d1730 100644 --- a/helper/pluginutils/loader/loader_test.go +++ b/helper/pluginutils/loader/loader_test.go @@ -103,7 +103,7 @@ func TestPluginLoader_External(t *testing.T) { require := require.New(t) // Create two plugins - plugins := []string{"mock-device", "mock-device-2"} + plugins := []string{"mock-device", "mock-device-2", "mock-device-3"} pluginVersions := []string{"v0.0.1", "v0.0.2"} h := newHarness(t, plugins) @@ -133,6 +133,8 @@ func TestPluginLoader_External(t *testing.T) { require.NoError(err) // Get the catalog and assert we have the two plugins + // + // Note: mock-device-3 is ignored because it does not have a related config. c := l.Catalog() require.Len(c, 1) require.Contains(c, base.PluginTypeDevice)