[Mono-bugs] [Bug 510852] New: FtpWebRequest crashes with out of range exception
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Jun 8 05:19:23 EDT 2009
http://bugzilla.novell.com/show_bug.cgi?id=510852
Summary: FtpWebRequest crashes with out of range exception
Classification: Mono
Product: Mono: Class Libraries
Version: 2.4.x
Platform: All
OS/Version: All
Status: NEW
Severity: Major
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: asl.pavel at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Description of Problem:
FtpWebRequest crashes with out of range exeception:
Unhandled Exception: System.IndexOutOfRangeException: Array index is out of
range.
at System.Net.FtpWebRequest.GetResponseStatus () [0x00000]
at System.Net.FtpWebRequest.Authenticate () [0x00000]
at System.Net.FtpWebRequest.OpenControlConnection () [0x00000]
at System.Net.FtpWebRequest.ProcessMethod () [0x00000]
at System.Net.FtpWebRequest.ProcessRequest () [0x00000]
I think problem in this snippet of code:
file: mcs/class/System/System.Net/FtpWebRequest.cs
string number: 1063
"
if (response == null || response.Length < 3)
return ServiceNotAvailable ();
int code;
if (!Int32.TryParse (response.Substring (0, 3), out code))
return ServiceNotAvailable ();
if (response [3] == '-'){
"
If server response with smth consisting only from 3 symbols, buth in the last
statement we try to access 4th symbol
Steps to reproduce the problem:
1. just connect to any server for example "bash$ nc -l -p 21"
2. and aswer with something like "220"
Actual Results:
OutOfRange Exception
Expected Results:
Invalid Response from server or smth like this
How often does this happen?
Always
Additional Information:
Example code:
using System.Net;
using System.IO;
using System;
class FtpSender {
const int BSize = 4096;
string HostName;
public FtpSender(string host) {
HostName = host;
}
public void Send(string localpath, string serverpath) {
string ftp_path = "ftp://" + HostName + serverpath;
FtpWebRequest ftp = (FtpWebRequest) FtpWebRequest.Create(ftp_path);
ftp.Credentials = new NetworkCredential("anonymous", "anonymous");
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
byte[] buffer = new byte[BSize];
int count;
using ( FileStream fs = File.OpenRead(localpath) ) {
using ( Stream ftps = ftp.GetRequestStream() ) {
while ( (count = fs.Read(buffer, 0, buffer.Length)) > 0 ) {
ftps.Write(buffer, 0, count);
}
}
}
}
}
class FtpSnederApp {
public static void Main(){
FtpSender fs = new FtpSender("192.168.1.10");
fs.Send("ftp.cs", "/ftp.cs" );
}
}
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list