curl-curl/lib/vtls
Viktor Szakats 51d8213579
core: stop redefining E* macros on Windows, map EACCES, related fixes
Before this patch, standard `E*` errno codes were redefined on Windows,
onto matching winsock2 `WSA*` error codes, which have different values.
This broke uses where using the `E*` value in non-socket context, or
other places expecting a POSIX `errno`, e.g. file I/O, threads, IDN or
interfacing with dependencies.

Fix it by introducing a curl-specific `SOCKE*` set of macros that map to
`WSA*` on Windows and standard POSIX codes on other platforms. Then
verify and update the code to use `SOCKE*` or `E*` macro depending on
context.

- Add `SOCKE*` macros that map to either winsock2 or POSIX error codes.
  And use them with `SOCKERRNO` or in contexts requiring
  platform-dependent socket error codes.

  This fixes `E*` uses which were supposed be POSIX values, not `WSA*`
  socket errors, on Windows:
  - lib/curl_multibyte.c
  - lib/curl_threads.c
  - lib/idn.c
  - lib/vtls/gtls.c
  - lib/vtls/rustls.c
  - src/tool_cb_wrt.c
  - src/tool_dirhie.c

- Ban `E*` codes having a `SOCKE*` mapping, via checksrc.
  Authored-by: Daniel Stenberg

- Add exceptions for `E*` codes used in file I/O, or other contexts
  requiring POSIX error codes.

Also:
- ftp: fix missing `SOCKEACCES` mapping for Windows.
- add `SOCKENOMEM` for `Curl_getaddrinfo()` via `asyn-thread.c`.
- tests/server/sockfilt: fix to set `SOCKERRNO` in local `select()`
  override on Windows.
- lib/inet_ntop: fix to return `WSAEINVAL` on Windows, where `ENOSPC` is
  used on other platforms. To simulate Windows' built-in `inet_ntop()`,
  as tested on a Win10 machine.
  Note:
  - WINE returns `STATUS_INVALID_PARAMETER` = `0xC000000D`.
  - Microsoft documentation says it returns `WSA_INVALID_PARAMETER`
    (= `ERROR_INVALID_PARAMETER`) 87:
    https://learn.microsoft.com/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop#return-value
- lib/inet_ntop: drop redundant `CURL_SETERRNO(ENOSPC)`.
  `inet_ntop4()` already sets it before returning `NULL`.
- replace stray `WSAEWOULDBLOCK` with `USE_WINSOCK` macro to detect
  winsock2.
- move existing `SOCKE*` mappings from `tests/server` to
  `curl_setup_once.h`.
- add missing `EINTR`, `EINVAL` constants for WinCE.

Follow-up to abf80aae38 #16612
Follow-up to d69425ed7d #16615
Bug: https://github.com/curl/curl/pull/16553#issuecomment-2704679377

Closes #16621
2025-03-13 00:03:25 +01:00
..
.checksrc strparse: switch to curl_off_t as base data type 2025-02-15 21:58:48 +01:00
bearssl.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
bearssl.h
cipher_suite.c vtls: fix compiler warnings seen with gcc 7.3.0 and mbedTLS 2025-03-07 15:43:00 +01:00
cipher_suite.h rustls: add support for setting TLS version and ciphers 2024-08-16 09:55:02 +02:00
gtls.c core: stop redefining E* macros on Windows, map EACCES, related fixes 2025-03-13 00:03:25 +01:00
gtls.h wolfssl: tls early data support 2025-02-24 10:01:51 +01:00
hostcheck.c code: language cleanup in comments 2024-07-01 22:58:55 +02:00
hostcheck.h code: language cleanup in comments 2024-07-01 22:58:55 +02:00
keylog.c lib: use bool/TRUE/FALSE properly 2024-10-03 09:31:56 +02:00
keylog.h
mbedtls_threadlock.c mbedtls: properly cleanup the thread-shared entropy 2024-03-12 03:09:37 -04:00
mbedtls_threadlock.h tidy-up: one comment and EOF newlines 2024-03-12 15:38:44 +00:00
mbedtls.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
mbedtls.h
openssl.c build: replace Curl_ prefix with curlx_ for functions used in servers 2025-03-13 00:03:15 +01:00
openssl.h OpenSSL/quictls: add support for TLSv1.3 early data 2025-03-03 09:27:04 +01:00
rustls.c core: stop redefining E* macros on Windows, map EACCES, related fixes 2025-03-13 00:03:25 +01:00
rustls.h
schannel_int.h schannel: fix TLS cert verification by IP SAN 2024-10-31 08:59:37 +01:00
schannel_verify.c build: replace Curl_ prefix with curlx_ for functions used in servers 2025-03-13 00:03:15 +01:00
schannel.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
schannel.h msvc: add missing push/pop for warning pragmas 2025-01-27 20:59:47 +01:00
sectransp.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
sectransp.h
vtls_int.h vtls: move common early data code into vtls.c 2025-02-26 16:00:37 +01:00
vtls_scache.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
vtls_scache.h build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
vtls_spack.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
vtls_spack.h build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
vtls.c build: replace Curl_ prefix with curlx_ for functions used in servers 2025-03-13 00:03:15 +01:00
vtls.h lib: TLS session ticket caching reworked 2024-12-20 14:59:23 +01:00
wolfssl.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
wolfssl.h wolfssl: tls early data support 2025-02-24 10:01:51 +01:00
x509asn1.c build: enable -Wcast-qual, fix or silence compiler warnings 2025-03-10 22:30:15 +01:00
x509asn1.h rustls: add support for CERTINFO 2025-02-25 07:59:39 +01:00