aboutsummaryrefslogtreecommitdiff
path: root/internal/ssh
diff options
context:
space:
mode:
authorwameidemao <u2nn@qq.com>2020-04-12 12:18:43 +0800
committerGitHub <noreply@github.com>2020-04-12 12:18:43 +0800
commitd19287d5b7826f0c1122a6ce29480a7ea5c40c27 (patch)
tree828f9d9957add607944c23ac2aa72e245bd11756 /internal/ssh
parent26a2d0b2a147162e2468696925daec038992cee8 (diff)
ssh: improve env command processing (#6095)
* modify ssh env command processing mode * Update internal/ssh/ssh.go Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io> * Update internal/ssh/ssh.go Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io> * Update internal/ssh/ssh.go Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io> * Update ssh.go Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Diffstat (limited to 'internal/ssh')
-rw-r--r--internal/ssh/ssh.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go
index cb9d5ed7..ff9fb8cc 100644
--- a/internal/ssh/ssh.go
+++ b/internal/ssh/ssh.go
@@ -51,20 +51,22 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
payload := cleanCommand(string(req.Payload))
switch req.Type {
case "env":
- args := strings.Split(strings.Replace(payload, "\x00", "", -1), "\v")
- if len(args) != 2 {
- log.Warn("SSH: Invalid env arguments: '%#v'", args)
+ var env struct {
+ Name string
+ Value string
+ }
+ if err := ssh.Unmarshal(req.Payload, &env); err != nil {
+ log.Warn("SSH: Invalid env payload %q: %v", req.Payload, err)
continue
}
- args[0] = strings.TrimLeft(args[0], "\x04")
-
// Sometimes the client could send malformed command (i.e. missing "="),
// see https://discuss.gogs.io/t/ssh/3106.
- if args[0] == "" {
+ if env.Name == "" || env.Value == "" {
+ log.Warn("SSH: Invalid env arguments: %+v", env)
continue
}
- _, stderr, err := com.ExecCmd("env", args[0]+"="+args[1])
+ _, stderr, err := com.ExecCmd("env", fmt.Sprintf("%s=%s", env.Name, env.Value))
if err != nil {
log.Error("env: %v - %s", err, stderr)
return