about summary refs log tree commit diff
path: root/src/libstd/sys/windows
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-02-23 23:22:58 -0800
committerAlex Crichton <alex@alexcrichton.com>2016-02-24 09:17:07 -0800
commitf3be73c84b546d975da8ec45671fa9e0e0ead8da (patch)
tree7697572e8381019253b882892ccae22d421097de /src/libstd/sys/windows
parent281f9d868fee8e4f9750fc12289dc10522f587ea (diff)
downloadrust-f3be73c84b546d975da8ec45671fa9e0e0ead8da.tar.gz
rust-f3be73c84b546d975da8ec45671fa9e0e0ead8da.zip
std: Cap read/write limits on Windows networking
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)