tq: verify connection and return error on nil

In some cases, we can end up with a panic due to a pure SSH transfer
lacking any connections, but it's not clear what those cases are.  Let's
add some explicit checks that our connection is functional and return an
error if not.
This commit is contained in:
brian m. carlson 2022-06-30 13:33:25 +00:00
parent 70b3fede8e
commit 91947ab05e
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -27,6 +27,9 @@ type SSHBatchClient struct {
func (a *SSHBatchClient) batchInternal(args []string, batchLines []string) (int, []string, []string, error) { func (a *SSHBatchClient) batchInternal(args []string, batchLines []string) (int, []string, []string, error) {
conn := a.transfer.Connection(0) conn := a.transfer.Connection(0)
if conn == nil {
return 0, nil, nil, errors.Errorf(tr.Tr.Get("could not get connection for batch request"))
}
conn.Lock() conn.Lock()
defer conn.Unlock() defer conn.Unlock()
err := conn.SendMessageWithLines("batch", args, batchLines) err := conn.SendMessageWithLines("batch", args, batchLines)
@ -179,6 +182,9 @@ func (a *SSHAdapter) DoTransfer(ctx interface{}, t *Transfer, cb ProgressCallbac
authOkFunc() authOkFunc()
} }
conn := ctx.(*ssh.PktlineConnection) conn := ctx.(*ssh.PktlineConnection)
if conn == nil {
return errors.Errorf(tr.Tr.Get("could not get connection for transfer"))
}
if a.adapterBase.direction == Upload { if a.adapterBase.direction == Upload {
return a.upload(t, conn, cb) return a.upload(t, conn, cb)
} else { } else {