curl/lib/curlx
Viktor Szakats 066478f634
src: add curlx_memzero() to clear buffers securely
To safely zero memory, introduce `curlx_memzero()`, and map it to
`memset_s()` (C11) or `memset_explicit()` (C23) if auto-detected, or
`explicit_bzero()` or `explicit_memset()` for platforms opted-in, or
fall back to a local workaround if all unavailable. On Windows, always
use `SecureZeroMemory()`, or `SecureZeroMemory2()` with Visual Studio
and Windows SDK 10.0.26100.0+.

Details above are experimental and may change if they cause issues.

Also add macros/functions that zero memory before freeing a buffer:
- `curlx_safefreezero()`: for buffers with size.
- `curlx_safefreezeroz()`: for null-terminated buffers.
- `curlx_freezero()`: for buffers with size.
- `curlx_freezeroz()`: for null-terminated buffers.

`curlx_memzero()` must not be passed a NULL pointer because in some
implementations it is undefined behavior.

Also:
- curl_sha512_256: Replace hard-wired `explicit_memset()` call with new
  `curlx_memzero()`.

Refs:
https://en.cppreference.com/c/string/byte/memset
https://man7.org/linux/man-pages/man3/explicit_bzero.3.html
https://man.freebsd.org/cgi/man.cgi?query=explicit_bzero
https://man.netbsd.org/NetBSD-7.2/explicit_memset.3
https://learn.microsoft.com/previous-versions/windows/desktop/legacy/aa366877(v=vs.85)
https://learn.microsoft.com/windows/win32/memory/winbase-securezeromemory2
https://learn.microsoft.com/cpp/overview/compiler-versions
https://learn.microsoft.com/windows/apps/windows-sdk/downloads
https://jtsoya539.github.io/windows-sdk-versions/

Credits-to: Daniel Gustafsson
Credits-to: Will Cosgrove and co-authors in libssh2
Ref: #13589 (original attempt)
Ref: #21588

Closes #21598
2026-05-16 00:26:46 +02:00
..
base64.c badwords: prefer 'null-terminated' 2026-03-18 11:40:13 +01:00
base64.h curlx: rename Curl_-prefixed symbols to curlx_ 2025-12-22 01:47:22 +01:00
basename.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
basename.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
dynbuf.c tidy-up: rename Curl_safefree()/tool_safefree() to curlx_safefree() 2026-04-01 19:53:53 +02:00
dynbuf.h clang-tidy: enable more checks, fix fallouts 2026-04-14 02:20:16 +02:00
fopen.c lib: reserve 'result' for CURLcode 2026-04-06 23:12:06 +02:00
fopen.h clang-tidy: enable more checks, fix fallouts 2026-04-14 02:20:16 +02:00
inet_ntop.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
inet_ntop.h clang-tidy: enable more checks, fix fallouts 2026-04-14 02:20:16 +02:00
inet_pton.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
inet_pton.h clang-tidy: add arg names to prototypes where missing (cont.) 2026-02-23 17:03:01 +01:00
multibyte.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
multibyte.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
nonblock.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
nonblock.h build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
snprintf.c gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings 2026-03-18 11:33:37 +01:00
snprintf.h curlx: add local snprintf() helper that always nul-terminates (Windows) 2026-03-02 21:30:36 +01:00
strcopy.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
strcopy.h curlx: curlx_strcopy() instead of strcpy() 2025-12-22 23:01:05 +01:00
strdup.c src: add curlx_memzero() to clear buffers securely 2026-05-16 00:26:46 +02:00
strdup.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
strerr.c tidy-up: prefer "initialize" with a 'z' 2026-05-15 11:49:06 +02:00
strerr.h curlx: move Curl_strerror, use in src and tests, ban strerror globally 2025-10-06 09:44:23 +02:00
strparse.c strparse: make curlx_str_until() accept zero for 'max' 2026-05-15 13:28:03 +02:00
strparse.h hsts: when a dupe host adds subdomains, use that 2026-03-26 23:27:24 +01:00
timediff.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
timediff.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
timeval.c curlx_now(), prevent zero timestamp 2026-03-21 14:47:36 +01:00
timeval.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
version_win32.c windows: determine RtlVerifyVersionInfo address on global init 2026-03-09 11:35:19 +01:00
version_win32.h windows: determine RtlVerifyVersionInfo address on global init 2026-03-09 11:35:19 +01:00
wait.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
wait.h lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
warnless.c lib: use lib source directory as base include path 2026-02-23 16:00:42 +01:00
warnless.h clang-tidy: sync argument names in prototype and definition 2026-02-19 12:44:37 +01:00
winapi.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
winapi.h windows: use native error code types more 2025-10-06 12:12:44 +02:00