From 8ffd94ca557a3461de0c1c6dfe75ddb30342cf7b Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Wed, 16 Jan 2019 15:22:03 +0100 Subject: [PATCH] plugins: Require an exe extension on windows --- plugins/shared/loader/filter_unix.go | 10 ++++++++++ plugins/shared/loader/filter_windows.go | 15 +++++++++++++++ plugins/shared/loader/init.go | 7 +------ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 plugins/shared/loader/filter_unix.go create mode 100644 plugins/shared/loader/filter_windows.go diff --git a/plugins/shared/loader/filter_unix.go b/plugins/shared/loader/filter_unix.go new file mode 100644 index 000000000..fefea7cb2 --- /dev/null +++ b/plugins/shared/loader/filter_unix.go @@ -0,0 +1,10 @@ +// +build !windows + +package loader + +import "os" + +// executable Checks to see if the file is executable by anyone. +func executable(path string, f os.FileInfo) bool { + return f.Mode().Perm()&0111 != 0 +} diff --git a/plugins/shared/loader/filter_windows.go b/plugins/shared/loader/filter_windows.go new file mode 100644 index 000000000..a3423c548 --- /dev/null +++ b/plugins/shared/loader/filter_windows.go @@ -0,0 +1,15 @@ +// +build windows + +package loader + +import ( + "os" + "path/filepath" +) + +// On windows, an executable can be any file with any extension. To avoid +// introspecting the file, here we skip executability checks on windows systems +// and simply check for the convention of an `exe` extension. +func executable(path string, s os.FileInfo) bool { + return filepath.Ext(path) == "exe" +} diff --git a/plugins/shared/loader/init.go b/plugins/shared/loader/init.go index 2795656a4..f61f47344 100644 --- a/plugins/shared/loader/init.go +++ b/plugins/shared/loader/init.go @@ -5,7 +5,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "sort" multierror "github.com/hashicorp/go-multierror" @@ -251,11 +250,7 @@ func (l *PluginLoader) scan() ([]os.FileInfo, error) { continue } - // Check if it is executable by anyone. On windows, an executable is any file with any - // extension and the file begins with MZ, however, there is no easy way for us to - // actually validate the executability of a file, so here we skip executability checks - // for windows systems. - if runtime.GOOS != "windows" && s.Mode().Perm()&0111 == 0 { + if !executable(f, s) { l.logger.Debug("skipping un-executable file in plugin folder", "file", f) continue }