curl/m4
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
..
.gitignore tidy-up: .gitignore lines mostly 2025-01-27 20:59:46 +01:00
curl-amissl.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-apple-sectrust.m4 autotools: tidy-up if expressions 2025-12-10 22:29:19 +01:00
curl-compilers.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-confopts.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-functions.m4 src: add curlx_memzero() to clear buffers securely 2026-05-16 00:26:46 +02:00
curl-gnutls.m4 gnutls: allow building with nettle 4.0 2026-05-12 03:54:24 +02:00
curl-mbedtls.m4 autotools: tidy-up if expressions 2025-12-10 22:29:19 +01:00
curl-openssl.m4 tidy-up: sort TLS backends, distros, alphabetically 2026-05-11 11:57:25 +02:00
curl-override.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-reentrant.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-rustls.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-schannel.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
curl-sysconfig.m4 autotools: tidy-up if expressions 2025-12-10 22:29:19 +01:00
curl-wolfssl.m4 curl_ntlm_core: use wolfCrypt DES API with wolfSSL 2026-04-07 11:58:30 +02:00
xc-am-iface.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
xc-cc-check.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
xc-lt-iface.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
xc-val-flgs.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
zz40-xc-ovr.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00
zz50-xc-ovr.m4 configure: tidy up comments 2026-04-10 23:19:41 +02:00