Skip to content

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

Open
@irwir

Description

@irwir

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcomponent-platformPortability layer and build scriptsgood-first-issueGood for newcomershelp-wantedThis issue is not being actively worked on, but PRs welcome.

    Type

    No type

    Projects

    Status

    No status

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions