add a recoverer where appropriate

I have never seen this, but a malformed packet can easily crash pkg/sftp
This commit is contained in:
Nicola Murino
2020-10-31 11:02:04 +01:00
parent fcfdd633f6
commit 950a5ad9ea
7 changed files with 73 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path"
"runtime/debug"
"strings"
"sync"
@@ -84,7 +85,13 @@ func processSSHCommand(payload []byte, connection *Connection, enabledSSHCommand
return false
}
func (c *sshCommand) handle() error {
func (c *sshCommand) handle() (err error) {
defer func() {
if r := recover(); r != nil {
logger.Error(logSender, "", "panic in handle ssh command: %#v stack strace: %v", r, string(debug.Stack()))
err = common.ErrGenericFailure
}
}()
common.Connections.Add(c.connection)
defer common.Connections.Remove(c.connection.GetID())
@@ -108,7 +115,7 @@ func (c *sshCommand) handle() error {
} else if c.command == "sftpgo-remove" {
return c.handeSFTPGoRemove()
}
return nil
return
}
func (c *sshCommand) handeSFTPGoCopy() error {