check for input termination before init packet

This commit is contained in:
sawka 2022-06-25 00:33:18 -07:00
parent fec7721e32
commit e8ae01efae

View File

@ -303,6 +303,7 @@ func RunClientSSHCommandAndWait(opts *ClientOpts) (*packet.CmdDonePacketType, er
stderrPacketCh := packet.PacketParser(stderrReader) stderrPacketCh := packet.PacketParser(stderrReader)
packetCh := packet.CombinePacketParsers(stdoutPacketCh, stderrPacketCh) packetCh := packet.CombinePacketParsers(stdoutPacketCh, stderrPacketCh)
sender := packet.MakePacketSender(inputWriter) sender := packet.MakePacketSender(inputWriter)
versionOk := false
for pk := range packetCh { for pk := range packetCh {
if pk.GetType() == packet.RawPacketStr { if pk.GetType() == packet.RawPacketStr {
rawPk := pk.(*packet.RawPacketType) rawPk := pk.(*packet.RawPacketType)
@ -314,9 +315,13 @@ func RunClientSSHCommandAndWait(opts *ClientOpts) (*packet.CmdDonePacketType, er
if initPk.Version != "0.1.0" { if initPk.Version != "0.1.0" {
return nil, fmt.Errorf("invalid remote mshell version 'v%s', must be v0.1.0", initPk.Version) return nil, fmt.Errorf("invalid remote mshell version 'v%s', must be v0.1.0", initPk.Version)
} }
versionOk = true
break break
} }
} }
if !versionOk {
return nil, fmt.Errorf("did not receive version from remote mshell")
}
runPacket := opts.MakeRunPacket() runPacket := opts.MakeRunPacket()
sender.SendPacket(runPacket) sender.SendPacket(runPacket)
if opts.Debug { if opts.Debug {