-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
use BOOL for TCP_NODELAY setsockopt value on Windows #94094
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon. Please see the contribution instructions for more information. |
33c1de8
to
e5f7239
Compare
Fixed footnote index in commit message... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bors r+ |
📌 Commit e5f7239 has been approved by |
I guess I didn't properly link this commit to #94092, since I made the commit before creating the issue. Should I update the commit message again to do so, or can someone with write perms link it for me? https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#manually-linking-a-pull-request-to-an-issue
Edit the second: thanks! |
…=dtolnay use BOOL for TCP_NODELAY setsockopt value on Windows This issue was found by the Wine project and mitigated there [^1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [^2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [^1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
…=dtolnay use BOOL for TCP_NODELAY setsockopt value on Windows This issue was found by the Wine project and mitigated there [^1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [^2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [^1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
@bors r- |
Agh, looks like the assertion in the getsockopt wrapper is complaining about the size. The docs say that the optval for TCP_NODELAY on getsockopt should also be BOOL (int), but this test failure suggests that getsockopt is setting *optlen to 1... I will investigate. |
So, I had tested the getsockopt change previously, but I was only testing on Wine, which does not modify |
Somewhat related, I noticed that the |
So to sum up the issue:
Is that about right? |
@ChrisDenton yes that's most of it. I believe that this patch as-is does fix Windows will accept >= 1 byte for I have patches to fix up the parameter names and to remove the assertion, but I wanted to get some feedback on whether this is the right path. I can push them here for review shortly. I'm not sure if there's a better way to check for mismatched sizes in a way that is more permissive but still useful; the |
Previously `level` was named `opt` and `option_name` was named `val`, then extra names of `payload` or `slot` were used for the option value. This change aligns the wrapper parameters with their names in POSIX. Winsock uses similar but more abbreviated names: `level`, `optname`, `optval`, `optlen`.
POSIX allows `getsockopt` to set `*option_len` to a smaller value if necessary. Windows will set `*option_len` to 1 for boolean options even when the caller passes a `BOOL` (`int`) with `*option_len` as 4.
This issue was found by the Wine project and mitigated there [1]. Windows' documented interface for `setsockopt` expects a `BOOL` (a `typedef` for `int`) for `TCP_NODELAY` [2]. Windows is forgiving and will accept any positive length and interpret the first byte of `*option_value` as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's `setsockopt`, where, e.g., Linux requires that `option_len` be correct for the chosen option, and `TCP_NODELAY` expects an `int`. [1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
e5f7239
to
b02698c
Compare
I've put two commits ahead of the original one. Appreciate any feedback, particularly on removing the assert. |
r? rust-lang/libs |
@bors r+ |
📌 Commit b02698c has been approved by |
Rollup of 7 pull requests Successful merges: - rust-lang#91545 (Generalize "remove `&`" and "add `*`" suggestions to more than one deref) - rust-lang#93385 (Rustdoc ty consistency fixes) - rust-lang#93926 (Lint against more useless `#[must_use]` attributes) - rust-lang#94094 (use BOOL for TCP_NODELAY setsockopt value on Windows) - rust-lang#94384 (Add Atomic*::from_mut_slice) - rust-lang#94448 (5 - Make more use of `let_chains`) - rust-lang#94452 (Sync portable-simd for bitmasks &c.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This issue was found by the Wine project and mitigated there 1.
Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY
2. Windows itself is forgiving and will accept any positive optlen and
interpret the first byte of *optval as the value, so this bug does not
affect Windows itself, but does affect systems implementing Windows'
interface more strictly, such as Wine. Wine was previously passing this
through to the host's setsockopt, where, e.g., Linux requires that
optlen be correct for the chosen option, and TCP_NODELAY expects an int.
Footnotes
https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 ↩
https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt ↩