From 26a2d0b2a147162e2468696925daec038992cee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=E1=B4=8B=C9=B4=E1=B4=A1=E1=B4=8F=C9=B4?= Date: Sun, 12 Apr 2020 09:18:58 +0800 Subject: [PATCH] ssh: ignore malformed "env" commands (#6094) --- internal/ssh/ssh.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go index a4d41d0f6..cb9d5ed7e 100644 --- a/internal/ssh/ssh.go +++ b/internal/ssh/ssh.go @@ -57,11 +57,19 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { continue } args[0] = strings.TrimLeft(args[0], "\x04") - _, _, err := com.ExecCmdBytes("env", args[0]+"="+args[1]) + + // Sometimes the client could send malformed command (i.e. missing "="), + // see https://discuss.gogs.io/t/ssh/3106. + if args[0] == "" { + continue + } + + _, stderr, err := com.ExecCmd("env", args[0]+"="+args[1]) if err != nil { - log.Error("env: %v", err) + log.Error("env: %v - %s", err, stderr) return } + case "exec": cmdName := strings.TrimLeft(payload, "'()") log.Trace("SSH: Payload: %v", cmdName)