Quantcast
Channel: sshnet Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1026

Edited Issue: OverflowException on empty server response [1562]

$
0
0
Hello,

I'm trying to connect to OS X Mountain Lion from a Windows Phone 7.5 application using a SFTP client implemented using your library (version 2013.4.7), and upon sftpclient.connect, after a few seconds of it apparently waiting for something, it crashes with OverflowException. Debugging in the source code the OverflowException is thrown in line 88 of Session.SilverlightShared.cs:
```
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```

At this point buffer.Count = 0, so buffer.Count -1 is actually -1.

Looking up it did break at:
```
// If zero bytes received then exit
if (args.BytesTransferred == 0)
break;
```

However in the subsequent tests that case doesn't seem handled:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```

So I added a simple line as follows and now I do get the "Server string is null or empty" exception as expected:

```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count == 0) response = string.Empty; // <-- this line right here
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```

Viewing all articles
Browse latest Browse all 1026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>