Skip to content

Commit 6e33d92

Browse files
committed
tighten up plugin-finding logic
Signed-off-by: Casey Callendrello <[email protected]>
1 parent 11db36c commit 6e33d92

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/invoke/find.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"os"
2020
"path/filepath"
21+
"strings"
2122
)
2223

2324
// FindInPath returns the full path of the plugin by searching in the provided path
@@ -26,6 +27,10 @@ func FindInPath(plugin string, paths []string) (string, error) {
2627
return "", fmt.Errorf("no plugin name provided")
2728
}
2829

30+
if strings.ContainsRune(plugin, os.PathSeparator) {
31+
return "", fmt.Errorf("invalid plugin name: %s", plugin)
32+
}
33+
2934
if len(paths) == 0 {
3035
return "", fmt.Errorf("no paths provided")
3136
}

pkg/invoke/find_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,13 @@ var _ = Describe("FindInPath", func() {
9999
Expect(err).To(MatchError(fmt.Sprintf("failed to find plugin %q in path %s", pluginName, pathsWithNothing)))
100100
})
101101
})
102+
103+
Context("When the plugin contains a directory separator", func() {
104+
It("returns an error", func() {
105+
bogusPlugin := ".." + string(os.PathSeparator) + "pluginname"
106+
_, err := invoke.FindInPath(bogusPlugin, []string{anotherTempDir})
107+
Expect(err).To(MatchError("invalid plugin name: " + bogusPlugin))
108+
})
109+
})
102110
})
103111
})

0 commit comments

Comments
 (0)