From f3be73c84b546d975da8ec45671fa9e0e0ead8da Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 23 Feb 2016 23:22:58 -0800 Subject: 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 --- src/libstd/sys/windows/net.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libstd/sys/windows') 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 { // 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) -- cgit 1.4.1-3-g733a5