-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Socket handle should use "unsigned" types on Windows #10097
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
Comments
Hi and thank you for your report. PR858 proposed a way for handling windows sockets but unfortunately it was never merged. Could you you please provide some more context on how it affects your system? is it compilation warnings you are getting while intergrating? This is a low priority issue and it is unlikely we will be able to do it soon. I am not however closing it, since we will happily accept community contributions on it (cherry picking the relevant commmit from the historic PR) |
Networking part was a step in the right direction, but invalid socket check was not fully correct.
It was described in the opening message, was it not? So I do not see how this issue could be tagged "help-wanted" and "good-first-issue" while a design decision was required in the first place. |
@irwir Would you be willing to propose a patch, at least for Going by your description (I'm not familiar with Windows APIs), it seems there is a definite bug on Windows, which could possibly remain latent until a new Windows version or a new system configuration causes it to use a socket handle that's outside the range [0, 2^31-1]. Do you have any suggestion on how to fix it? If there's no other reasonable way, a Windows-only (64-bit-Windows-only?) ABI change might be acceptable, we'd have to discuss this further. Would the in-memory layout of Regarding #858, it had a very ambitious objective, which in itself is not very important (just warnings, lots of warnings). In fact I would consider |
Re: PR858. The adjective ambitious applies naturally here. The fix was still partial, some warnings had to be disabled. Other warnings, like related to type casts, were fine to accept for cleaner code.
Certain values were promised by MS to be 32 bits even in 64-bit platforms, but never saw such claims about socket handles, let alone to keep the value within 31 bits. Then it is a bug, even if never seen in practice.
A suggestion exists in the mentioned PR #1427. The changes for sockets mostly touch net_socket.* files. Please take a look to recall the general idea. |
If it's never seen in practice, then I think we won't fix it in 3.6 (which only has about two years left of support). But 4.0 would be a good time to future-proof against future evolution of Windows.
Sorry. Unfortunately the answer is always “we don't have time for this” 😞 . But a pull request that changes 3 files would have a much bigger chance than one that changes 22 files.
I'm not sure why anything would be needed outside of So would you mind making a pull request with just the socket part? I think we can find time for that. The Unicode names on the other hand would be a very hard sell. |
Winsock2 must be included before other Windows definitions to avoid defaulting to Winsock1.
Development is heavily biased towards *nix, while Windows still has a noticeable share of library users. |
That sounds bad. I guess you're referring to #8490 ? It's not clear to me in this thread what is wrong. Would you be willing to submit a patch for that? With explanations for reviewers who aren't at all familiar with Windows, please.
Not really. Most of us know Unix better than Windows, but the platforms that are prioritized (both in terms of library architecture and in terms of developer time) are embedded platforms such as microcontrollers and trusted enclaves. We develop and test primarily on Linux because it's convenient, but it isn't really our main target platform.
Oh, ideally, yes, absolutely. But I want to be realistic. Fixing file name encoding when reading a certificate database just isn't going to have enough priority that it gets reviewed. A relatively simple patch that fixes a potential major bug (socket) or a security weakness (zeroize) has a reasonable chance. |
Question, 'What was right?' might be asked. With the attempted macro, Visual Studio could not compile the library, then would not link.
This is fine, however, combination of better knowledge of Unix, usage of typical Unix toolchain, common references to limited Windows experience - mostly confirm my point.
The larger gets the library, the more efforts were required to straighten things out (all mentioned PRs were made in 2018). When calling the library, on Windows user applications have to convert paths from native UTF-16LE to ANSI. Back to sockets; design question. |
Test build of the VS solution passed successfully with all |
Resolves Mbed-TLS#10097. Signed-off-by: irwir <[email protected]>
Resolves Mbed-TLS#10097. Signed-off-by: irwir <[email protected]>
Resolves Mbed-TLS#10097. Signed-off-by: irwir <[email protected]>
Resolves Mbed-TLS#10097. Signed-off-by: irwir <[email protected]>
Summary
Networking implementation in the library follows POSIX standards, but the same code is used on Windows too.
mbedtls/include/mbedtls/net_sockets.h
Line 90 in f19a08f
There are no standard options to change this declaration, though Windows declares socket as unsigned pointer-sized integer.
The current code has two negative properties:
System information
Mbed TLS version (number or commit id): any
Operating system and version: Windows
Configuration (if not default, please attach
mbedtls_config.h
):Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
Additional environment information:
Expected behavior
Using native socket type and error checks on Windows.
Actual behavior
Mbedtls always uses 32-bit signed integer for sockets; any negative value means
invalid socket
.Signed/unsigned mismatch and truncation/expansion of values are commonly diagnosed by compilers and static analysers.
The text was updated successfully, but these errors were encountered: