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

Socket handle should use "unsigned" types on Windows #10097

Open
irwir opened this issue Mar 27, 2025 · 0 comments
Open

Socket handle should use "unsigned" types on Windows #10097

irwir opened this issue Mar 27, 2025 · 0 comments

Comments

@irwir
Copy link
Contributor

irwir commented Mar 27, 2025

Summary

Networking implementation in the library follows POSIX standards, but the same code is used on Windows too.


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:

  • Implicit type casts between 32-bit/64-bit unsigned integers and 32-bit signed integers - with potential loss of data.
  • Check for invalid socket is not quite correct, because there is one specific value on Windows, not any negative number.

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.

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

No branches or pull requests

1 participant