about summary refs log tree commit diff
path: root/src/libstd/sys/windows
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-26 15:42:44 +0000
committerbors <bors@rust-lang.org>2016-02-26 15:42:44 +0000
commit1aa6ac38b2ca725a3b0a0379a554e953ca783298 (patch)
tree10497df427c593542ce095b85b9b6929ab3967b0 /src/libstd/sys/windows
parentf59fd4642534e80a61982ce3e10c147d97054212 (diff)
parentf3be73c84b546d975da8ec45671fa9e0e0ead8da (diff)
downloadrust-1aa6ac38b2ca725a3b0a0379a554e953ca783298.tar.gz
rust-1aa6ac38b2ca725a3b0a0379a554e953ca783298.zip
Auto merge of #31858 - alexcrichton:fix-networking-cast, r=brson
Similar to #31825 where the read/write limits were capped for files, this
implements similar limits when reading/writing networking types. On Unix this
shouldn't affect anything because the write size is already a `usize`, but on
Windows this will cap the read/write amounts to `i32::max_value`.

cc #31841
Diffstat (limited to 'src/libstd/sys/windows')
-rw-r--r--src/libstd/sys/windows/net.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs
index 3e69902dcb6..49ba8e9c659 100644
--- a/src/libstd/sys/windows/net.rs
+++ b/src/libstd/sys/windows/net.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use cmp;
 use io;
 use libc::{c_int, c_void};
 use mem;
@@ -131,9 +132,9 @@ impl Socket {
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
         // On unix when a socket is shut down all further reads return 0, so we
         // do the same on windows to map a shut down socket to returning EOF.
+        let len = cmp::min(buf.len(), i32::max_value() as usize) as i32;
         unsafe {
-            match c::recv(self.0, buf.as_mut_ptr() as *mut c_void,
-                             buf.len() as i32, 0) {
+            match c::recv(self.0, buf.as_mut_ptr() as *mut c_void, len, 0) {
                 -1 if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0),
                 -1 => Err(last_error()),
                 n => Ok(n as usize)