libuv/src/win
Matheus Izvekov 9b3b61f606
build: ubsan fixes (#4254)
MSVC does not actually support ubsan. There is a long-standing ticket
requesting this:
https://developercommunity.visualstudio.com/t/add-support-for-ubsan/840750

There are no known compilers that currently accept the
`/fsanitize=undefined` spelling. clang-cl accepts `-fsanitize...`,
same as regular clang.

Also passes no-sanitizer-recover so that tests actually fail.

Fix various ubsan-detected errors, including:

* win: fix req-inl.h ubsan failure

Don't use CONTAINING_RECORD macro from WinSDK, as it doesn't use the
right trick which avoids member access on null pointer.

Fixes:
```
src/win/req-inl.h:86:10: runtime error: member access within null pointer of type 'uv_req_t' (aka 'struct uv_req_s')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior D:/a/libuv/libuv/src/win/req-inl.h:86:10
```

* test: fix ubsan failure on udp_ref3

Don't call functions through different function type.

Fixes:
```
src/win/udp.c:537:5: runtime error: call to function req_cb through pointer to incorrect function type 'void (*)(struct uv_udp_send_s *, int)'
test\test-ref.c:66: note: req_cb defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/udp.c:537:5 in
```

* win: fix process-stdio.c ubsan failure

When accessing HANDLEs within the stdio buffer, use memcpy / memset in order to respect alignment.

Fixes:
```
src/win/process-stdio.c:197:5: runtime error: store to misaligned address 0x0230ee72d107 for type 'HANDLE' (aka 'void *'), which requires 8 byte alignment
0x0230ee72d107: note: pointer points here
  00 00 cd cd cd  cd cd cd cd cd cd cd cd  cd cd cd cd cd cd cd cd  cd cd cd cd cd cd cd fd  fd fd fd
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/process-stdio.c:197:5 in
```

* win: fix getaddrinfo.c ubsan failure

Reworks buffer alignment handling to respect requirements.

Fixes:
```
src/win/getaddrinfo.c:157:23: runtime error: member access within misaligned address 0x0290e4c6a17c for type 'struct addrinfo', which requires 8 byte alignment
0x0290e4c6a17c: note: pointer points here
  00 00 00 00 cd cd cd cd  cd cd cd cd cd cd cd cd  cd cd cd cd cd cd cd cd  cd cd cd cd cd cd cd cd
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/getaddrinfo.c:157:23 in
```

* win: fix pipe.c ubsan failure

Changes "random" representation from pointer to number.

Fixes:
```
src/win/pipe.c:234:11: runtime error: applying non-zero offset to non-null pointer 0xffffffffffffffff produced null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/pipe.c:234:11 in
```

* unix: fix stream.c ubsan failure

Avoids performing pointer arithmetic on null pointer.

Fixes:
```
src/unix/stream.c:701:15: runtime error: applying zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/runner/work/libuv/libuv/src/unix/stream.c:701:15 in
```
2024-08-05 17:15:53 -04:00
..
async.c win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
atomicops-inl.h mingw: fix building for ARM/AArch64 2021-07-14 12:36:30 -04:00
core.c src: don't run timers if loop is stopped/unref'd (#4048) 2023-06-16 11:00:06 -06:00
detect-wakeup.c nfci: address some style nits 2020-08-21 17:25:42 -04:00
dl.c misc: export WTF8 conversion utilities (#4021) 2023-10-28 21:04:57 -04:00
error.c win,error: remap ERROR_NO_DATA to EAGAIN (#4471) 2024-07-29 16:16:49 -04:00
fs-event.c fsevents: detect watched directory removal (#4376) 2024-07-30 00:59:38 +02:00
fs-fd-hash-inl.h nfci: address some style nits 2020-08-21 17:25:42 -04:00
fs.c win,fs: use the new Windows fast stat API (#4327) 2024-07-30 08:58:41 -04:00
getaddrinfo.c build: ubsan fixes (#4254) 2024-08-05 17:15:53 -04:00
getnameinfo.c unix,win: remove unused req parameter from macros (#4435) 2024-07-11 21:29:15 +02:00
handle-inl.h unix,win: replace QUEUE with struct uv__queue (#4022) 2023-05-25 00:04:30 +02:00
handle.c win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
internal.h misc: export WTF8 conversion utilities (#4021) 2023-10-28 21:04:57 -04:00
loop-watcher.c win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
pipe.c build: ubsan fixes (#4254) 2024-08-05 17:15:53 -04:00
poll.c win: drop code checking for Windows XP / Server 2k3 2022-11-08 06:51:07 +01:00
process-stdio.c build: ubsan fixes (#4254) 2024-08-05 17:15:53 -04:00
process.c win: remove _alloca usage (#4361) 2024-03-20 12:09:37 +01:00
req-inl.h build: ubsan fixes (#4254) 2024-08-05 17:15:53 -04:00
signal.c win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
snprintf.c win: fix compilation with VS < 2012 2015-10-01 00:41:41 +02:00
stream-inl.h win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
stream.c unix,win: remove unused req parameter from macros (#4435) 2024-07-11 21:29:15 +02:00
tcp.c unix,win: remove unused req parameter from macros (#4435) 2024-07-11 21:29:15 +02:00
thread.c win: simplify uv_once implementation 2024-03-25 11:57:52 +01:00
tty.c win,signal: fix data race dispatching SIGWINCH (#4488) 2024-08-05 16:32:31 -04:00
udp.c unix,win: remove unused req parameter from macros (#4435) 2024-07-11 21:29:15 +02:00
util.c win: fix env var in uv_os_homedir and uv_os_tmpdir (#4464) 2024-07-29 17:50:11 -04:00
winapi.c win,fs: use the new Windows fast stat API (#4327) 2024-07-30 08:58:41 -04:00
winapi.h win,fs: use the new Windows fast stat API (#4327) 2024-07-30 08:58:41 -04:00
winsock.c win: fix style nits [NFC] (#3474) 2022-02-15 10:13:24 -05:00
winsock.h win,mingw: Fix undefined MCAST_* constants 2019-09-25 14:48:10 +02:00