diff options
author | Dick Porter <dick@acm.org> | 2002-10-08 18:05:51 +0400 |
---|---|---|
committer | Dick Porter <dick@acm.org> | 2002-10-08 18:05:51 +0400 |
commit | bb0b26f43ac27b10433b228f64cedea23c7853a4 (patch) | |
tree | 6dd4fb8600d020bb731aa10ad14d856c41a545cc /mcs/class/System/System.Net.Sockets | |
parent | 2d68045cbdbe49d8329f50c5bb1ed055731394b6 (diff) |
2002-10-08 Dick Porter <dick@ximian.com>
* Socket.cs:
* NetworkStream.cs: Bounds checking fixes, and better exception
texts. Changes by timothyjmills@hotmail.com (Timothy J. Mills).
svn path=/trunk/mcs/; revision=8062
Diffstat (limited to 'mcs/class/System/System.Net.Sockets')
-rw-r--r-- | mcs/class/System/System.Net.Sockets/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/class/System/System.Net.Sockets/NetworkStream.cs | 47 | ||||
-rw-r--r-- | mcs/class/System/System.Net.Sockets/Socket.cs | 46 |
3 files changed, 70 insertions, 29 deletions
diff --git a/mcs/class/System/System.Net.Sockets/ChangeLog b/mcs/class/System/System.Net.Sockets/ChangeLog index 5299ea619b7..82c2103ea72 100644 --- a/mcs/class/System/System.Net.Sockets/ChangeLog +++ b/mcs/class/System/System.Net.Sockets/ChangeLog @@ -1,3 +1,9 @@ +2002-10-08 Dick Porter <dick@ximian.com> + + * Socket.cs: + * NetworkStream.cs: Bounds checking fixes, and better exception + texts. Changes by timothyjmills@hotmail.com (Timothy J. Mills). + 2002-10-03 Dick Porter <dick@ximian.com> * TcpClient.cs: NoDelay is a TCP option, not Socket diff --git a/mcs/class/System/System.Net.Sockets/NetworkStream.cs b/mcs/class/System/System.Net.Sockets/NetworkStream.cs index d304795eef3..ea74bb6e254 100644 --- a/mcs/class/System/System.Net.Sockets/NetworkStream.cs +++ b/mcs/class/System/System.Net.Sockets/NetworkStream.cs @@ -36,7 +36,7 @@ namespace System.Net.Sockets public NetworkStream (Socket socket, FileAccess access, bool owns_socket) { if (socket == null) - throw new ArgumentNullException (); + throw new ArgumentNullException ("socket is null"); if (!socket.Connected) throw new ArgumentException ("Not connected", "socket"); if (socket.SocketType != SocketType.Stream) @@ -133,10 +133,14 @@ namespace System.Net.Sockets IAsyncResult retval; if (buffer == null) - throw new ArgumentNullException (); + throw new ArgumentNullException ("buffer is null"); int len = buffer.Length; - if (offset >= len || size != len) - throw new ArgumentOutOfRangeException (); + if(offset<0 || offset>=len) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); + } + if(offset+size<0 || offset+size>len) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); + } try { retval = socket.BeginReceive (buffer, offset, size, 0, callback, state); @@ -157,11 +161,15 @@ namespace System.Net.Sockets IAsyncResult retval; if (buffer == null) - throw new ArgumentNullException (); + throw new ArgumentNullException ("buffer is null"); int len = buffer.Length; - if (len < size) - throw new ArgumentException (); + if(offset<0 || offset>=len) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); + } + if(offset+size<0 || offset+size>len) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); + } try { retval = socket.BeginSend (buffer, offset, size, 0, callback, state); @@ -205,7 +213,7 @@ namespace System.Net.Sockets int res; if (ar == null) - throw new ArgumentNullException (); + throw new ArgumentNullException ("async result is null"); try { res = socket.EndReceive (ar); @@ -222,7 +230,7 @@ namespace System.Net.Sockets { try { if (ar == null) - throw new ArgumentNullException (); + throw new ArgumentNullException ("async result is null"); try { socket.EndSend (ar); @@ -251,9 +259,13 @@ namespace System.Net.Sockets int res; if (buffer == null) - throw new ArgumentNullException (); - if (buffer.Length < size) - throw new ArgumentException (); + throw new ArgumentNullException ("buffer is null"); + if(offset<0 || offset>=buffer.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); + } + if(offset+size < 0 || offset+size>buffer.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); + } try { res = socket.Receive (buffer, offset, size, 0); @@ -284,9 +296,14 @@ namespace System.Net.Sockets { try { if (buffer == null) - throw new ArgumentNullException (); - if (buffer.Length < size) - throw new ArgumentException (); + throw new ArgumentNullException ("buffer is null"); + if(offset<0 || offset>=buffer.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); + } + if(offset+size<0 || offset+size>buffer.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); + } + try { socket.Send (buffer, offset, size, 0); } catch { diff --git a/mcs/class/System/System.Net.Sockets/Socket.cs b/mcs/class/System/System.Net.Sockets/Socket.cs index 85c72df0d84..a9ebb84021e 100644 --- a/mcs/class/System/System.Net.Sockets/Socket.cs +++ b/mcs/class/System/System.Net.Sockets/Socket.cs @@ -709,10 +709,13 @@ namespace System.Net.Sockets public int Receive(byte[] buf, int offset, int size, SocketFlags flags) { if(buf==null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("buffer is null"); + } + if(offset<0 || offset >= buf.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); } - if(offset+size>buf.Length) { - throw new ArgumentException(); + if(offset+size<0 || offset+size > buf.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); } int ret; @@ -758,11 +761,17 @@ namespace System.Net.Sockets public int ReceiveFrom(byte[] buf, int offset, int size, SocketFlags flags, ref EndPoint remote_end) { - if(buf==null || remote_end==null) { - throw new ArgumentNullException(); + if(buf==null) { + throw new ArgumentNullException("buffer is null"); + } + if(remote_end==null) { + throw new ArgumentNullException("remote endpoint is null"); + } + if(offset<0 || offset>=buf.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); } - if(offset+size>buf.Length) { - throw new ArgumentException(); + if(offset+size<0 || offset+size>buf.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); } SocketAddress sockaddr=remote_end.Serialize(); @@ -806,10 +815,13 @@ namespace System.Net.Sockets public int Send(byte[] buf, int offset, int size, SocketFlags flags) { if(buf==null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("buffer is null"); + } + if(offset<0 || offset>=buf.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); } - if(offset+size>buf.Length) { - throw new ArgumentException(); + if(offset+size<0 || offset+size>buf.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); } int ret; @@ -854,11 +866,17 @@ namespace System.Net.Sockets public int SendTo(byte[] buffer, int offset, int size, SocketFlags flags, EndPoint remote_end) { - if(buffer==null || remote_end==null) { - throw new ArgumentNullException(); + if(buffer==null) { + throw new ArgumentNullException("buffer is null"); + } + if(remote_end==null) { + throw new ArgumentNullException("remote endpoint is null"); + } + if(offset<0 || offset>=buffer.Length) { + throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); } - if(offset+size>buffer.Length) { - throw new ArgumentException(); + if(offset+size<0 || offset+size>buffer.Length) { + throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); } SocketAddress sockaddr=remote_end.Serialize(); |