mirror of https://github.com/pkg/sftp.git
Fix panic when connection dropped in the middle of the sid
This commit is contained in:
parent
6181f5c673
commit
053574d9eb
|
@ -239,3 +239,21 @@ func TestClientShortPacket(t *testing.T) {
|
||||||
t.Fatalf("expected error: %v, got: %v", errShortPacket, err)
|
t.Fatalf("expected error: %v, got: %v", errShortPacket, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #418: panic in clientConn.recv when the sid is incomplete.
|
||||||
|
func TestClientNoSid(t *testing.T) {
|
||||||
|
stream := new(bytes.Buffer)
|
||||||
|
sendPacket(stream, &sshFxVersionPacket{Version: sftpProtocolVersion})
|
||||||
|
// Next packet has the sid cut short after two bytes.
|
||||||
|
stream.Write([]byte{0, 0, 0, 10, 0, 0})
|
||||||
|
|
||||||
|
c, err := NewClientPipe(stream, &sink{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = c.Stat("anything")
|
||||||
|
if !errors.Is(err, ErrSSHFxConnectionLost) {
|
||||||
|
t.Fatal("expected ErrSSHFxConnectionLost, got", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
5
conn.go
5
conn.go
|
@ -84,7 +84,10 @@ func (c *clientConn) recv() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sid, _ := unmarshalUint32(data)
|
sid, _, err := unmarshalUint32Safe(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
ch, ok := c.getChannel(sid)
|
ch, ok := c.getChannel(sid)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue