curl/lib
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
..
curlx
vauth
vquic
vssh
vtls
.gitignore
altsvc.c
altsvc.h
amigaos.c
amigaos.h
arpa_telnet.h
asyn-ares.c
asyn-base.c
asyn-thrdd.c
asyn.h
bufq.c
bufq.h
bufref.c
bufref.h
cf-dns.c
cf-dns.h
cf-h1-proxy.c
cf-h1-proxy.h
cf-h2-proxy.c
cf-h2-proxy.h
cf-haproxy.c
cf-haproxy.h
cf-https-connect.c
cf-https-connect.h
cf-ip-happy.c
cf-ip-happy.h
cf-socket.c
cf-socket.h
cfilters.c
cfilters.h
CMakeLists.txt
config-mac.h
config-os400.h
config-riscos.h
config-win32.h
conncache.c
conncache.h
connect.c
connect.h
content_encoding.c
content_encoding.h
cookie.c
cookie.h
creds.c
creds.h creds: add sasl service name 2026-05-13 14:04:17 +02:00
cshutdn.c
cshutdn.h
curl_addrinfo.c lib: introduce Curl_peer 2026-05-05 16:22:11 +02:00
curl_addrinfo.h
curl_config-cmake.h.in
curl_ctype.h
curl_endian.c
curl_endian.h
curl_fnmatch.c
curl_fnmatch.h
curl_fopen.c
curl_fopen.h
curl_get_line.c
curl_get_line.h
curl_gethostname.c
curl_gethostname.h
curl_gssapi.c
curl_gssapi.h
curl_hmac.h
curl_ldap.h
curl_md4.h
curl_md5.h
curl_memrchr.c
curl_memrchr.h
curl_ntlm_core.c
curl_ntlm_core.h
curl_printf.h
curl_range.c
curl_range.h
curl_sasl.c
curl_sasl.h
curl_setup.h
curl_sha256.h
curl_sha512_256.c
curl_sha512_256.h
curl_share.c
curl_share.h
curl_sspi.c
curl_sspi.h
curl_threads.c
curl_threads.h
curl_trc.c
curl_trc.h
cw-out.c
cw-out.h
cw-pause.c
cw-pause.h
dict.c
dict.h
dllmain.c
dnscache.c
dnscache.h
doh.c
doh.h
dynhds.c
dynhds.h lib: move all UNITTEST prototypes to C files (cont.) 2026-03-21 13:14:46 +01:00
easy.c
easy_lock.h
easygetopt.c
easyif.h
easyoptions.c
easyoptions.h
escape.c
escape.h
fake_addrinfo.c
fake_addrinfo.h
file.c
file.h
fileinfo.c
fileinfo.h
formdata.c
formdata.h
ftp-int.h
ftp.c
ftp.h
ftplistparser.c
ftplistparser.h
functypes.h
getenv.c
getinfo.c
getinfo.h
gopher.c
gopher.h
hash.c
hash.h
headers.c
headers.h
hmac.c
hostip.c
hostip.h
hostip4.c
hostip6.c
hsts.c
hsts.h
http.c
http.h
http1.c
http1.h
http2.c
http2.h
http_aws_sigv4.c
http_aws_sigv4.h
http_chunks.c
http_chunks.h
http_digest.c
http_digest.h
http_negotiate.c
http_negotiate.h
http_ntlm.c
http_ntlm.h
http_proxy.c
http_proxy.h
httpsrr.c
httpsrr.h
idn.c
idn.h
if2ip.c
if2ip.h
imap.c
imap.h
ldap.c
libcurl.def
libcurl.rc
libcurl.vers.in
llist.c
llist.h
macos.c
macos.h
Makefile.am
Makefile.inc
Makefile.soname
md4.c
md5.c
memdebug.c
mime.c
mime.h
mprintf.c
mqtt.c creds: hold credentials 2026-05-12 16:05:15 +02:00
mqtt.h
multi.c
multi_ev.c
multi_ev.h
multi_ntfy.c
multi_ntfy.h
multihandle.h
multiif.h
netrc.c
netrc.h
noproxy.c
noproxy.h
openldap.c
optiontable.pl
parsedate.c
parsedate.h
peer.c
peer.h
pingpong.c
pingpong.h
pop3.c
pop3.h
progress.c
progress.h
protocol.c
protocol.h
psl.c
psl.h
rand.c
rand.h
ratelimit.c
ratelimit.h
request.c
request.h
rtsp.c
rtsp.h
select.c
select.h
sendf.c
sendf.h
setopt.c
setopt.h
setup-os400.h
setup-vms.h
setup-win32.h
sha256.c
sigpipe.h
slist.c
slist.h
smb.c
smb.h
smtp.c
smtp.h
sockaddr.h
socketpair.c
socketpair.h
socks.c
socks.h
socks_gssapi.c
socks_sspi.c
splay.c
splay.h
strcase.c
strcase.h
strequal.c
strerror.c
strerror.h
system_win32.c
system_win32.h
telnet.c
telnet.h
tftp.c
tftp.h
thrdpool.c
thrdpool.h
thrdqueue.c
thrdqueue.h
transfer.c
transfer.h
uint-bset.c
uint-bset.h
uint-hash.c
uint-hash.h
uint-spbset.c
uint-spbset.h
uint-table.c
uint-table.h
url.c
url.h
urlapi-int.h
urlapi.c
urldata.h
version.c
ws.c
ws.h