Skip to content

Commit 91947ab

Browse files
committed
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.
1 parent 70b3fed commit 91947ab

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tq/ssh.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type SSHBatchClient struct {
2727

2828
func (a *SSHBatchClient) batchInternal(args []string, batchLines []string) (int, []string, []string, error) {
2929
conn := a.transfer.Connection(0)
30+
if conn == nil {
31+
return 0, nil, nil, errors.Errorf(tr.Tr.Get("could not get connection for batch request"))
32+
}
3033
conn.Lock()
3134
defer conn.Unlock()
3235
err := conn.SendMessageWithLines("batch", args, batchLines)
@@ -179,6 +182,9 @@ func (a *SSHAdapter) DoTransfer(ctx interface{}, t *Transfer, cb ProgressCallbac
179182
authOkFunc()
180183
}
181184
conn := ctx.(*ssh.PktlineConnection)
185+
if conn == nil {
186+
return errors.Errorf(tr.Tr.Get("could not get connection for transfer"))
187+
}
182188
if a.adapterBase.direction == Upload {
183189
return a.upload(t, conn, cb)
184190
} else {

0 commit comments

Comments
 (0)