@@ -891,6 +891,43 @@ func TestSCPInvalidEndDir(t *testing.T) {
891891 assert .EqualError (t , err , "unacceptable end dir command" )
892892}
893893
894+ func TestSCPMessageSizeLimit (t * testing.T ) {
895+ stdErrBuf := make ([]byte , 65535 )
896+ connection := & Connection {
897+ BaseConnection : common .NewBaseConnection ("" , common .ProtocolSCP , "" , "" , dataprovider.User {
898+ BaseUser : sdk.BaseUser {
899+ HomeDir : os .TempDir (),
900+ },
901+ }),
902+ }
903+ scpCommand := scpCommand {
904+ sshCommand : sshCommand {
905+ command : "scp" ,
906+ connection : connection ,
907+ args : []string {"-t" , "/tmp" },
908+ },
909+ }
910+
911+ protocolMsg := bytes .Repeat ([]byte ("A" ), maxSCPMessageSize + 1 )
912+ connection .channel = & MockChannel {
913+ Buffer : bytes .NewBuffer (protocolMsg ),
914+ StdErrBuffer : bytes .NewBuffer (stdErrBuf ),
915+ }
916+ _ , err := scpCommand .readProtocolMessage ()
917+ assert .ErrorContains (t , err , "scp protocol message too long" )
918+
919+ confirmationMsg := append ([]byte {warnMsg [0 ]}, bytes .Repeat ([]byte ("A" ), maxSCPMessageSize + 1 )... )
920+ connection .channel = & MockChannel {
921+ Buffer : bytes .NewBuffer (confirmationMsg ),
922+ StdErrBuffer : bytes .NewBuffer (stdErrBuf ),
923+ }
924+ err = scpCommand .readConfirmationMessage ()
925+ assert .ErrorContains (t , err , "scp error message too long" )
926+
927+ assert .Len (t , common .Connections .GetStats ("" ), 0 )
928+ assert .Equal (t , int32 (0 ), common .Connections .GetTotalTransfers ())
929+ }
930+
894931func TestSCPParseUploadMessage (t * testing.T ) {
895932 buf := make ([]byte , 65535 )
896933 stdErrBuf := make ([]byte , 65535 )
0 commit comments