Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Cap read/write limits on Windows networking #31858

Merged
merged 1 commit into from
Feb 26, 2016

Conversation

alexcrichton
Copy link
Member

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

@alexcrichton
Copy link
Member Author

cc @ollie27

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -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 i32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing an as usize.
May as well make this line match the others:
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh oops good catch! I also figured it's better to use i32 here as it's what's actually required for the system call (eg this is windows specific).

I'm not a huge fan of the usage of wrlen_t in general unfortunately...

Similar to rust-lang#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 rust-lang#31841
@brson
Copy link
Contributor

brson commented Feb 25, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Feb 25, 2016

📌 Commit f3be73c has been approved by brson

@bors
Copy link
Contributor

bors commented Feb 26, 2016

⌛ Testing commit f3be73c with merge 1aa6ac3...

bors added a commit that referenced this pull request Feb 26, 2016
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
@bors bors merged commit f3be73c into rust-lang:master Feb 26, 2016
@alexcrichton alexcrichton deleted the fix-networking-cast branch March 1, 2016 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants