From f5c90a02e6f098a425292a303467d5e11159d9e4 Mon Sep 17 00:00:00 2001 From: Russell Jones Date: Wed, 19 Apr 2017 10:17:04 -0700 Subject: [PATCH] Removed shell parsing for scp code as well. --- Godeps/Godeps.json | 5 - lib/srv/exec.go | 8 +- .../mattn/go-shellwords/.travis.yml | 8 - .../github.com/mattn/go-shellwords/README.md | 47 ------ .../mattn/go-shellwords/shellwords.go | 145 ------------------ .../mattn/go-shellwords/util_posix.go | 19 --- .../mattn/go-shellwords/util_windows.go | 17 -- 7 files changed, 2 insertions(+), 247 deletions(-) delete mode 100644 vendor/github.com/mattn/go-shellwords/.travis.yml delete mode 100644 vendor/github.com/mattn/go-shellwords/README.md delete mode 100644 vendor/github.com/mattn/go-shellwords/shellwords.go delete mode 100644 vendor/github.com/mattn/go-shellwords/util_posix.go delete mode 100644 vendor/github.com/mattn/go-shellwords/util_windows.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 8f5c5f8e88c..533b6d80009 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -366,11 +366,6 @@ "ImportPath": "github.com/mailgun/ttlmap", "Rev": "16b258d86efc53ac5cf3e550604f566c32624fab" }, - { - "ImportPath": "github.com/mattn/go-shellwords", - "Comment": "v1.0.2", - "Rev": "005a0944d84452842197c2108bd9168ced206f78" - }, { "ImportPath": "github.com/mdp/rsc/gf256", "Rev": "90f07065088deccf50b28eb37c93dad3078c0f3c" diff --git a/lib/srv/exec.go b/lib/srv/exec.go index 619d2bcd2ed..2dbed49cba2 100644 --- a/lib/srv/exec.go +++ b/lib/srv/exec.go @@ -40,7 +40,6 @@ import ( log "github.com/Sirupsen/logrus" "github.com/kardianos/osext" - "github.com/mattn/go-shellwords" ) const ( @@ -79,11 +78,8 @@ func parseExecRequest(req *ssh.Request, ctx *ctx) (*execResponse, error) { return nil, trace.BadParameter("failed to parse exec request, error: %v", err) } - // split up command like a shell would do for us - args, err := shellwords.Parse(e.Command) - if err != nil { - return nil, trace.Wrap(err) - } + // split up command by space to grab the first word + args := strings.Split(e.Command, " ") if len(args) > 0 { _, f := filepath.Split(args[0]) diff --git a/vendor/github.com/mattn/go-shellwords/.travis.yml b/vendor/github.com/mattn/go-shellwords/.travis.yml deleted file mode 100644 index 16d1430aa22..00000000000 --- a/vendor/github.com/mattn/go-shellwords/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: - - tip -before_install: - - go get github.com/mattn/goveralls - - go get golang.org/x/tools/cmd/cover -script: - - $HOME/gopath/bin/goveralls -repotoken 2FMhp57u8LcstKL9B190fLTcEnBtAAiEL diff --git a/vendor/github.com/mattn/go-shellwords/README.md b/vendor/github.com/mattn/go-shellwords/README.md deleted file mode 100644 index 56f357fad7f..00000000000 --- a/vendor/github.com/mattn/go-shellwords/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# go-shellwords - -[![Coverage Status](https://coveralls.io/repos/mattn/go-shellwords/badge.png?branch=master)](https://coveralls.io/r/mattn/go-shellwords?branch=master) -[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords) - -Parse line as shell words. - -## Usage - -```go -args, err := shellwords.Parse("./foo --bar=baz") -// args should be ["./foo", "--bar=baz"] -``` - -```go -os.Setenv("FOO", "bar") -p := shellwords.NewParser() -p.ParseEnv = true -args, err := p.Parse("./foo $FOO") -// args should be ["./foo", "bar"] -``` - -```go -p := shellwords.NewParser() -p.ParseBacktick = true -args, err := p.Parse("./foo `echo $SHELL`") -// args should be ["./foo", "/bin/bash"] -``` - -```go -shellwords.ParseBacktick = true -p := shellwords.NewParser() -args, err := p.Parse("./foo `echo $SHELL`") -// args should be ["./foo", "/bin/bash"] -``` - -# Thanks - -This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse::CommandLine). - -# License - -under the MIT License: http://mattn.mit-license.org/2014 - -# Author - -Yasuhiro Matsumoto (a.k.a mattn) diff --git a/vendor/github.com/mattn/go-shellwords/shellwords.go b/vendor/github.com/mattn/go-shellwords/shellwords.go deleted file mode 100644 index 107803927ae..00000000000 --- a/vendor/github.com/mattn/go-shellwords/shellwords.go +++ /dev/null @@ -1,145 +0,0 @@ -package shellwords - -import ( - "errors" - "os" - "regexp" -) - -var ( - ParseEnv bool = false - ParseBacktick bool = false -) - -var envRe = regexp.MustCompile(`\$({[a-zA-Z0-9_]+}|[a-zA-Z0-9_]+)`) - -func isSpace(r rune) bool { - switch r { - case ' ', '\t', '\r', '\n': - return true - } - return false -} - -func replaceEnv(s string) string { - return envRe.ReplaceAllStringFunc(s, func(s string) string { - s = s[1:] - if s[0] == '{' { - s = s[1 : len(s)-1] - } - return os.Getenv(s) - }) -} - -type Parser struct { - ParseEnv bool - ParseBacktick bool - Position int -} - -func NewParser() *Parser { - return &Parser{ParseEnv, ParseBacktick, 0} -} - -func (p *Parser) Parse(line string) ([]string, error) { - args := []string{} - buf := "" - var escaped, doubleQuoted, singleQuoted, backQuote bool - backtick := "" - - pos := -1 - got := false - -loop: - for i, r := range line { - if escaped { - buf += string(r) - escaped = false - continue - } - - if r == '\\' { - if singleQuoted { - buf += string(r) - } else { - escaped = true - } - continue - } - - if isSpace(r) { - if singleQuoted || doubleQuoted || backQuote { - buf += string(r) - backtick += string(r) - } else if got { - if p.ParseEnv { - buf = replaceEnv(buf) - } - args = append(args, buf) - buf = "" - got = false - } - continue - } - - switch r { - case '`': - if !singleQuoted && !doubleQuoted { - if p.ParseBacktick { - if backQuote { - out, err := shellRun(backtick) - if err != nil { - return nil, err - } - buf = out - } - backtick = "" - backQuote = !backQuote - continue - } - backtick = "" - backQuote = !backQuote - } - case '"': - if !singleQuoted { - doubleQuoted = !doubleQuoted - continue - } - case '\'': - if !doubleQuoted { - singleQuoted = !singleQuoted - continue - } - case ';', '&', '|', '<', '>': - if !(escaped || singleQuoted || doubleQuoted || backQuote) { - pos = i - break loop - } - } - - got = true - buf += string(r) - if backQuote { - backtick += string(r) - } - } - - if got { - if p.ParseEnv { - buf = replaceEnv(buf) - } - args = append(args, buf) - } - - if escaped || singleQuoted || doubleQuoted || backQuote { - return nil, errors.New("invalid command line string") - } - - p.Position = pos - - return args, nil -} - -func Parse(line string) ([]string, error) { - return NewParser().Parse(line) -} diff --git a/vendor/github.com/mattn/go-shellwords/util_posix.go b/vendor/github.com/mattn/go-shellwords/util_posix.go deleted file mode 100644 index 4f8ac55e478..00000000000 --- a/vendor/github.com/mattn/go-shellwords/util_posix.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !windows - -package shellwords - -import ( - "errors" - "os" - "os/exec" - "strings" -) - -func shellRun(line string) (string, error) { - shell := os.Getenv("SHELL") - b, err := exec.Command(shell, "-c", line).Output() - if err != nil { - return "", errors.New(err.Error() + ":" + string(b)) - } - return strings.TrimSpace(string(b)), nil -} diff --git a/vendor/github.com/mattn/go-shellwords/util_windows.go b/vendor/github.com/mattn/go-shellwords/util_windows.go deleted file mode 100644 index 7cad4cf06fd..00000000000 --- a/vendor/github.com/mattn/go-shellwords/util_windows.go +++ /dev/null @@ -1,17 +0,0 @@ -package shellwords - -import ( - "errors" - "os" - "os/exec" - "strings" -) - -func shellRun(line string) (string, error) { - shell := os.Getenv("COMSPEC") - b, err := exec.Command(shell, "/c", line).Output() - if err != nil { - return "", errors.New(err.Error() + ":" + string(b)) - } - return strings.TrimSpace(string(b)), nil -}