Skip to content

Commit

Permalink
Merge pull request #811 from squeed/plugin-name-0.8
Browse files Browse the repository at this point in the history
tighten up plugin-finding logic
  • Loading branch information
dcbw authored Feb 2, 2021
2 parents 11db36c + 6e33d92 commit 9fc34ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/invoke/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
)

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

if strings.ContainsRune(plugin, os.PathSeparator) {
return "", fmt.Errorf("invalid plugin name: %s", plugin)
}

if len(paths) == 0 {
return "", fmt.Errorf("no paths provided")
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/invoke/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,13 @@ var _ = Describe("FindInPath", func() {
Expect(err).To(MatchError(fmt.Sprintf("failed to find plugin %q in path %s", pluginName, pathsWithNothing)))
})
})

Context("When the plugin contains a directory separator", func() {
It("returns an error", func() {
bogusPlugin := ".." + string(os.PathSeparator) + "pluginname"
_, err := invoke.FindInPath(bogusPlugin, []string{anotherTempDir})
Expect(err).To(MatchError("invalid plugin name: " + bogusPlugin))
})
})
})
})

0 comments on commit 9fc34ae

Please sign in to comment.