Commit Graph

16434 Commits

Author SHA1 Message Date
Stefan Eissing
aeee5dd616
connection bits: move 'connect_only' here
Move the bit `connection_only` from `connectdata` to `ConnectBits`.
Since we keep all other bits there, seems the correct place.

Closes #20959
2026-03-17 15:01:29 +01:00
Daniel Stenberg
e894699c1e
strerr: correct the strerror_s() return code condition
In curlx_strerror on Windows, the condition checks `!strerror_s(...)`
(true on success) and therefore always evaluates the fallback block.
Even when strerror_s successfully produced a valid errno message.

Follow-up to 1eca08a541

Pointed out by Codex Security
Closes #20955
2026-03-17 14:45:01 +01:00
Viktor Szakats
3e74a3e062
openssl: drop obsolete SSLv2 logic
Closes #20945
2026-03-17 14:36:54 +01:00
Flavio Amieiro
fa5d2cc97e
curl_ctype.h: fix spelling in a couple of locally used macros
The `ISLOWHEXALHA` and `ISUPHEXALHA` macros were introduced in commit
f65f750 and seem to be only referenced locally by the `ISXDIGIT` macro.

Judging by the `ISALPHA` macro defined in the same file, it seems like
the intention was to spell them as `IS.*HEXALPHA`.

I noticed this while reading through the code and decided to open a PR,
even if it is only a tiny change, just because I was already looking at
it and it might be useful. If there is any reason not to merge this,
please do close the PR.

Closes #20810
2026-03-17 14:34:48 +01:00
Stefan Eissing
2e2d021d97
ftp: do not strdup DATA hostname
Since `newhost` is already allocated, we do not need to strdup()
it. Just assign and NULL the reference.

Closes #20953
2026-03-17 13:42:25 +01:00
Daniel Stenberg
b98981e16b
url: don't assume all transfers have hostnames
Follow-up from 412cd2577a

Add test 1659 to verify --connect-to when doing file:// transfers.

Reported-by: James Fuller
Closes #20948
2026-03-17 10:26:35 +01:00
Daniel Stenberg
3e8df37885
digest: pass in the user name quoted (as well)
For cases where the user puts a double quote or backspace in the user
name.

Adjusted test 907 to verify

Reported-by: am-perip on hackerone

Closes #20940
2026-03-16 22:43:14 +01:00
Viktor Szakats
9d104f566f
ldap: drop duplicate ldap_set_option() on Windows
Already set after `ldap_sslinit()`/`ldap_init()` and before
`ldap_ssl`-specific initialization.

Follow-up to 39d1976b7f #19830
Follow-up to b41e65a8e3
Follow-up to b91421b107

Closes #20930
2026-03-16 13:18:45 +01:00
Viktor Szakats
030d6aeaf3
build: include curlx headers directly in src and tests
To include what's actually used.

Also:
- drop unused includes.
- scope includes where possible.
- drop `curlx/curlx.h` umbrella header.
- config2setopts: include `netinet/in.h` for Cygwin/MSYS2.
  Previously included by chance via an unused curlx include.

Closes #20776
2026-03-16 12:05:39 +01:00
Viktor Szakats
e76968e20d
curl_get_line: fix potential infinite loop when filename is a directory
Fix potential inifinite loop reading file content with `Curl_get_line()`
when a filename passed via these options are pointing to a directory
entry (on non-Windows):

- `--alt-svc` / `CURLOPT_ALTSVC`
- `-b` / `--cookie` / `CURLOPT_COOKIEFILE`
- `--hsts` / `CURLOPT_HSTS`
- `--netrc-file` / `CURLOPT_NETRC_FILE`

Fix by checking for this condition and silently skipping such filename
without attempting to read content. Add test 1713 to verify.

Mention in cookie documentation as an accepted case, also show a verbose
message when a directory is detected. Extend test 46 to verify if such
failure lets the logic continue to the next cookie file.

Reported-and-based-on-patch-by: Richard Tollerton
Fixes #20823
Closes #20826 (originally-based-on)
Follow-up to 769ccb4d42 #19140

Closes #20873
2026-03-16 11:54:43 +01:00
Viktor Szakats
6d87eb2878
cmake: add CURL_GCC_ANALYZER option, enable in CI, fix/silence
Enable in one existing Linux, macOS and Windows job.

Cost:
- Linux: +1.3 minutes.
- macOS: +1.5 minutes.
- Windows: +2.5 minutes.

Fix or silence issues found:
- conncache: silence NULL deref warning.
  ```
  lib/conncache.c:564:18: warning: dereference of NULL '*data.multi' [CWE-476] [-Wanalyzer-null-dereference]
  ```
  Ref: ede6a8e087 #19378
- http2: check pointer for NULL.
  ```
  lib/http2.c:388:7: error: dereference of NULL ‘data’ [CWE-476] [-Wanalyzer-null-dereference]
  ```
- http2: silence potential NULL deref in `cf_h2_recv`.
  ```
  lib/http2.c: In function 'cf_h2_recv':
  lib/curl_trc.h:62:15: warning: dereference of NULL 'data' [CWE-476] [-Wanalyzer-null-dereference]
  ```
- openldap: silence deref before NULL check.
  Seen in GHA/Linux.
  ```
  lib/openldap.c: In function ‘oldap_state_mechs_resp’:
  lib/curl_trc.h:140:7: warning: check of ‘data’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check]
  ```
- sendf: silence NULL deref false positive in `Curl_creader_set_fread`.
  It looks impossible to happen.
  ```
  lib/sendf.c:1133:7: warning: dereference of NULL 'r' [CWE-476] [-Wanalyzer-null-dereference]
  ```
- ws: silence deref before NULL check.
  ```
  lib/ws.c: In function 'ws_send_raw_blocking':
  lib/curl_trc.h:205:7: warning: check of 'data' for NULL after already dereferencing it [-Wanalyzer-deref-before-check]
  ```
- var: fix potential NULL deref
  ```
  src/var.c:216:29: warning: dereference of NULL 'envp' [CWE-476] [-Wanalyzer-null-dereference]
  ```
- cli_hx_upload.c: fix NULL check after dereference.
  ```
  tests/libtest/cli_hx_upload.c:170:7: warning: check of '*t.method' for NULL after already dereferencing it [-Wanalyzer-deref-before-check]
  ```
- unit1607, unit1609: fix theoretical NULL ptr dereference.
  ```
  tests/unit/unit1607.c:211:12: warning: dereference of NULL 'addr' [CWE-476] [-Wanalyzer-null-dereference]
  tests/unit/unit1609.c:193:12: warning: dereference of NULL 'addr' [CWE-476] [-Wanalyzer-null-dereference]
  ```
- globally disable checks triggering false positives only:
  ```
  docs/examples/externalsocket.c:135:8: warning: 'connect' on possibly invalid file descriptor 'sockfd' [-Wanalyzer-fd-use-without-check]
  lib/bufq.c:465:16: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop] (gcc-15 Windows)
  lib/doh.c:1035:34: warning: stack-based buffer over-read [CWE-126] [-Wanalyzer-out-of-bounds] (gcc-15 macOS)
  lib/ftp.c:4022:20: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop] (gcc-15 macOS)
  lib/http2.c:689:28: warning: buffer over-read [CWE-126] [-Wanalyzer-out-of-bounds] (gcc-15 macOS)
  lib/socketpair.c:195:5: warning: leak of file descriptor 'curl_dbg_socket(2, 1, 0, 192, "D:/a/curl/curl/lib/socketpair.c")' [CWE-775] [-Wanalyzer-fd-leak]
  src/tool_doswin.c:810:7: warning: leak of file descriptor '*tdata.socket_l' [CWE-775] [-Wanalyzer-fd-leak]
  src/tool_doswin.c:816:9: warning: leak of file descriptor '*tdata.socket_l' [CWE-775] [-Wanalyzer-fd-leak]
  src/tool_main.c:96:1: warning: leak of file descriptor 'fd[0]' [CWE-775] [-Wanalyzer-fd-leak]
  src/tool_main.c:96:1: warning: leak of file descriptor 'fd[1]' [CWE-775] [-Wanalyzer-fd-leak]
  src/tool_urlglob.c:48:17: warning: leak of 'malloc(8)' [CWE-401] [-Wanalyzer-malloc-leak]
  src/tool_writeout.c:870:3: warning: leak of FILE 'stream2' [CWE-775] [-Wanalyzer-file-leak]
  tests/libtest/lib518.c:90:1: warning: leak of FILE [CWE-775] [-Wanalyzer-file-leak]
  tests/libtest/lib537.c:87:1: warning: leak of FILE [CWE-775] [-Wanalyzer-file-leak]
  tests/server/tftpd.c:1147:10: warning: 'bind' on possibly invalid file descriptor 'sock' [-Wanalyzer-fd-use-without-check]
  tests/server/tftpd.c:1155:10: warning: 'bind' on possibly invalid file descriptor 'sock' [-Wanalyzer-fd-use-without-check]
  tests/server/tftpd.c:1259:10: warning: 'connect' on possibly invalid file descriptor '4294967295' [-Wanalyzer-fd-use-without-check]
  ```

Also:
- cmake: update clang-tidy typecheck comment.

Ref: https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html

Closes #20921
2026-03-16 11:49:34 +01:00
Viktor Szakats
6b0a885611
ldap: fix to initialize cleartext connection on Windows
Regression since curl 8.18.0.

Reported-by: Yoshiro Yoneya
Fixes #20927
Follow-up to 39d1976b7f #19830

Closes #20928
2026-03-16 11:30:45 +01:00
Daniel Stenberg
0cd0e193d3
url: use URL for url even in comments
(Missed in CI due to a bug, see #20934)

Closes #20935
2026-03-16 10:51:02 +01:00
Martin Dürrmeier
594a9276bc
docs/lib: fix typos
Repated 'the the' and 'with with'

Closes #20933
2026-03-16 10:43:24 +01:00
Stefan Eissing
eb14705280
protocol source, all about protocols and uri schemes
Add protocol.h and protocol.c containing all about libcurl's
known URI schemes and their protocol handlers (so they exist).

Moves the scheme definitions from the various sources files into
protocol.c. Schemes are known and used, even of the protocol
handler is not build or just not implemented at all.

Closes #20906
2026-03-16 08:39:02 +01:00
Daniel Stenberg
32531f20f9
doh: fix memory-leak when doing a second DoH resolve
Reported-by: James Fuller
Closes #20929
2026-03-16 00:20:18 +01:00
Stefan Eissing
f50446f6da
lib: keepon improving
Improve the name, type and handling of `data->req.keepon`:

- Rename `keepon` to `io_flags`
- make `io_flags` and `uint8_t` and reposition in struct
- Rename `KEEP_*` defines to `REQ_IO_*`, move to request.h
- Replace all direct bit tests to `CURL_REQ_WANT_*` use
- Replace all direct bit manipulations with new macros

Closes #20905
2026-03-15 12:48:03 +01:00
Stefan Eissing
9325eb5fc4
urldata: import port types and conn destination format
Convert more `int port` to `uint16_t` port types. Reshuffle ports in
connectdata to save some bytes. Change `conn->destination` format to

- make it more readable and thus usable in tracing
- add the IPv6 scope_id only when not default (global)
  and make it resemble more the textual format for IPv6
  (e.g. suffix '%<scope_id>')

Closes #20918
2026-03-15 12:02:26 +01:00
Stefan Eissing
412cd2577a
urldata: connection bit ipv6_ip is wrong
Eliminate `conn->bits.ipv6_ip`

The bit was only correct for the first transfer using a connection. Use
`data->state.up.hostname` instead in places that need the URL hostname
in its original form.

Fix parseurlandfillconn() to not modify `data->state.up.hostname` before
copying the connection's hostname, but modify the copy instead, leaving
the URL hostname intact.

Closes #20919
2026-03-14 23:17:40 +01:00
Daniel Stenberg
9148862c26
test1626: Curl_copy_header_value unit test
Closes #20903
2026-03-12 13:59:59 +01:00
Viktor Szakats
7a4fa90048
openssl: trace count of found / imported Windows native CA roots
To help understanding what's happening on systems where native CA misses
to verify legitimate public websites.

Also:
- drop a superfluous, hanging, `else`.

Ref: #20897

Closes #20899
2026-03-12 10:49:21 +01:00
Daniel Stenberg
133b125b89
http: make Curl_compareheader handle multiple commas in header
For robustness
2026-03-12 10:30:18 +01:00
Daniel Stenberg
ed7bfcd17d
test1625: unit test for Curl_compareheader
Follow-up to 2938cb72e5

Closes #20901
2026-03-12 10:30:14 +01:00
Daniel Stenberg
c0f17dee36
hostip: remove two zero assigns after memset clear
As the struct is now always unconditionally memset with zeros, we
can remove two zero assigns.

Follow-up to 015f1c7de4

Pointed out by CodeSonar

Closes #20900
2026-03-12 08:47:02 +01:00
Daniel Stenberg
2938cb72e5
http: fix Curl_compareheader for multi value headers
Follow-up to 04289c62de. Regression shipped in 8.13.0.

- a logic error made it not loop and thus only match if the searched string
  was first

- it no longer matches a substring

Adjusted test 1 to use multiple values in the Connection: response
header. Adjusted test 1542 to have a "Connection: close-not" which
should not match.

Reported-by: Henrique Pereira

Closes #20894
2026-03-12 07:52:58 +01:00
Viktor Szakats
435eabeac8
badwords: rework exceptions, fix many of them
Also:
- support per-directory and per-upper-directory whitelist entries.
- convert badlist input grep tweak into the above format.
  (except for 'And' which had just a few hits.)
- fix many code exceptions, but do not enforce.
  (there also remain about 350 'will' uses in lib)
- fix badwords in example code, drop exceptions.
- badwords-all: convert to Perl.
  To make it usable from CMake.
- FAQ: reword to not use 'will'. Drop exception.

Closes #20886
2026-03-12 01:01:16 +01:00
Daniel Stenberg
11c14b5ca5
urlapi: verify the last letter of a scheme when set explictly
A logic error made the function not check the last character, which thus
could make it accept invalid schemes.

Added test 1965 to verify

Reported-by: Otis Cui Lei

Closes #20893
2026-03-11 23:48:53 +01:00
Stefan Eissing
5fc7d50cec
vtls: ECH definitions cleanup
- Move ECH related defines to vtls.h
- Prefix all defines with `CURLECH_`
- Move base64.h include from vtls.h to implementations

Closes #20887
2026-03-11 23:45:29 +01:00
Stefan Eissing
f14ce01369
pingpong: cleanup timeleft handling
- Move `RESP_TIMEOUT` from urldata.h to pingpong.h as
  `PINGPONG_TIMEOUT_MS`.
- Rename `Curl_pp_state_timeout()` to `Curl_pp_state_timeleft_ms()` as
  the function returns the time left, not the timout..
- Update implementation comments and variable names

Closes #20888
2026-03-11 23:30:05 +01:00
Stefan Eissing
da7bfb89a1
connection_check, simplified
The protocol handler method `connection_check` allowed to variable
operations to trigger with variable result bits. Only the `CONNCHECK_ISDEAD`
and `CONNRESULT_DEAD` were in use. Transform the function into
`connection_is_dead` without extra parameter and a bool result.

- Remove defines for `CONNCHECK_*` and `CONNRESULT_*`
- Rename protocol function in handler comments
- Change RTSP implementation (only protocol that uses this)

Closes #20890
2026-03-11 23:28:50 +01:00
Vladimír Marek
015f1c7de4
hostip: clear the sockaddr_in6 structure before use
On Solaris this was causing intermittent issues when the private
structure member __sin6_src_id had unexpectedly some value. connect(2)
would then fail with EADDRNOTAVAIL.

Closes #20885
2026-03-11 11:33:13 +01:00
Daniel Stenberg
53a3b2114a
libssh2: fix error handling on quote errors
Previously it lacked the actual return. libssh.c uses the same function
name.

Verified by test 2007.

Reported-by: m777m0 on hackerone

Follow-up to 578706adde

Closes #20883
2026-03-11 09:44:21 +01:00
Felipe Mesquita
f25124338c
badwords: avoid 'simply'
It's mostly a filler word. I've read through each use of it in the code
base and did minor rephrasings when "simply" carried some meaning. The
overwhelming majority of cases, removing it improved the text
significantly. Inspired by #20793.

Closes #20822
2026-03-10 19:34:06 +01:00
Daniel Stenberg
248dd9e55f
x509asn1: make encodeOID stop on too long input
Plus a minor fixup.

Reported-by: John Rodriguez

Closes #20871
2026-03-09 22:06:45 +01:00
Viktor Szakats
716dc8ce6c
rand: drop scan-build silencer
scan-build has been dropped in favor of clang-tidy and this false
positive no longer triggers with it.

Follow-up to ce4db9c2ef #20751
Follow-up to 02f207a76b

Closes #20860
2026-03-09 11:35:19 +01:00
Viktor Szakats
05189f5549
rand: drop impossible preprocessor branches (wincrypt)
After targeting Vista as minimum, the non-bcrypt fallback code was
impossible to reach, because on UWP wincrypt is never available.

After this patch it's more obvious that no-SSL UWP builds only support
weak random source.

Follow-up to b17ef873ae #18009

Closes #20859
2026-03-09 11:35:19 +01:00
Viktor Szakats
6a09f2ef1d
config-win32.h: merge two #if branches
Closes #20856
2026-03-09 11:35:19 +01:00
Viktor Szakats
6a6826469d
windows: determine RtlVerifyVersionInfo address on global init
Instead of the first internal call to `curlx_verify_windows_version()`.

To avoid the chance of a race, potentially resulting in initializing
this address twice. AFAICT it could not cause an issue before this
patch.

Reported by Codex Security

Follow-up to b17ef873ae #18009

Closes #20853
2026-03-09 11:35:19 +01:00
Viktor Szakats
ccba492024
tidy-up: miscellaneous
Closes #20851
2026-03-09 11:35:19 +01:00
huanghuihui0904
cbb5544c45
digest: fix memory leak in auth_create_digest_http_message()
Signed-off-by: huanghuihui0904 <625173@qq.com>

Closes #20862
2026-03-09 09:24:01 +01:00
Stefan Eissing
e090be9f73
smb: free the path in the request struct properly
Closes #20854
2026-03-08 22:43:03 +01:00
Viktor Szakats
64d4f5c4b6
system_win32: replace manual init code with curlx_now_init() call
The code actual init code remains identical after this patch. To make it
clearer where this initialization is called from, and to dedupe code.

Follow-up to b17ef873ae #18009

Closes #20852
2026-03-08 18:17:11 +01:00
dbalsom
9a674ee6f7
docs: replace instances of the vague qualifier 'quite'
in documentation and comments

Closes #20841
2026-03-07 23:52:50 +01:00
Daniel Stenberg
13f48dfb52
docs: avoid starting sentences with However,
An unnecessary filling word

Closes #20834
2026-03-07 23:49:11 +01:00
Daniel Stenberg
6b552e60a9
quiche: use PRIu64 for outputting the stream id
The 'id' struct field in 'struct h3_stream_ctx' is a uint64_t type so
should be output with PRIu64 - and it makes sense to be consistent.

Note that the field with the same name in the ngtcp2 version of this
struct is a *signed* 64-bit variable.

Reported by Codex Security

Closes #20849
2026-03-07 23:47:56 +01:00
Daniel Stenberg
08d6497005
cf-socket: ignore SOCK_CLOEXEC etc for socktype equality checks
As the SOCK_CLOEXEC and SOCK_NONBLOCK get ORed to the socktype, this
introduces the cf_socktype() function to use when checking for the
specific socket type: DGRAM or STREAM. The function filters off the
non-type related bits to enable the comparison.

Follow-up to 05367694ec

Closes #20808
2026-03-07 13:36:00 +01:00
Daniel Stenberg
e3d7401a32
http: only send bearer if auth is allowed
Verify with test 2006

Closes #20843
2026-03-07 11:00:16 +01:00
Daniel Stenberg
1495489c41
docs: drop basically
Another filler word

Closes #20835
2026-03-07 10:58:36 +01:00
Stefan Eissing
704e7a85f3
mqtt: fix EOF handling
In mqtt_recv_atleast(), recognize an EOF as error.

Fixes #20815
Reported-by: Max Dymond
Closes #20830
2026-03-06 22:53:54 +01:00
Stefan Eissing
5f13a7645e
proxy-auth: additional tests
Also eliminate the special handling for socks proxy match.

Closes #20837
2026-03-06 22:52:39 +01:00
Daniel Stenberg
e47b6e657a
socketpair: clear 'err' when retrying due to EINTR
If the first write was interrupted by a signal and a subsequent write
succeeds, the function would still erroneously return EINTR.

Found by Codex Security
Closes #20809
2026-03-06 22:50:29 +01:00
Daniel Stenberg
27c3e0839a
content_encoding: return 'identity' if none other exists
This fixes a regression and accidental changed behavior shipped in
8.18.0 (via 6b9c75e219).

When the setopt is set to "" and curl is built without support for a
single compression algorithm, it used to use "identity" but recently did
not.

Spotted by Codex Security
Closes #20805
2026-03-06 22:48:16 +01:00
Stefan Eissing
3c007d6351
openssl+ech: workaround for insecure handshakes
OpenSSL 4.0.0-dev supports ECH with one flaw. If peer verification
is not enabled, it will report SSL_ECH_STATUS_BAD_NAME on the ECH
status.

Provide a workaround in libcurl that checks the inner name used in
ECH was the peer's hostname, both verify peer and host are disabled
and then accept the BAD_NAME without failing the connect.

Fixes #20655
Reported-by: Dexter Gerig
Closes #20821
2026-03-06 22:42:40 +01:00
Stefan Eissing
b803dc9f20
async-ares: blocking resolve timeout handling, better
Perform the actual timeout calculation in the blocking resolv
loop each time in the same way, keeping the logic simpler.

The previous version calculated the timeout once, and then
reduced it by the elapsed time spent in polling/processing.
This is unnecessarily complicated.

Closes #20819
2026-03-06 22:41:56 +01:00
Stefan Eissing
bfb79de206
urldata: byebye conn->hostname_resolve
The strdup() of the hostname to resolve is unnecessary as the sync
resolve code does not keep the string and the async code makes copies
already.

Remove the member from `connectdata`.

Closes #20833
2026-03-06 22:40:29 +01:00
Max Dymond
70ec11358c socks: ensure DNS is freed in failure cases.
In several error cases in socks.c the DNS struct is not freed, which
leads to memory leaks.

Found by: OSS-Fuzz: 447858136

Closes #20813
2026-03-04 17:33:06 +00:00
Daniel Stenberg
ad58e07b54
curl.h: remove CURLPROTO_MQTTS from the public header
- the value collided with the internal one used for WebSocket
- we add all new ones as internal bits
- bump to 64-bit internal type
- introduce new define for setting all protocols (CURLPROTO_64ALL)

Reported by Codex Security

Closes #20798
2026-03-03 23:14:34 +01:00
Daniel Stenberg
7577ed7e86
schannel: fix UAF in client cert store thumbprint handling
Follow-up to 10bb489b22

Found by Codex Security
Closes #20801
2026-03-03 22:14:26 +01:00
Daniel Stenberg
d9c2c64337
openssl: adapt to OpenSSL master adding const to more APIs
Closes #20797
2026-03-03 17:42:34 +01:00
Daniel Stenberg
3d708e239b
urlapi: use U_CURLU_URLDECODE when toggling it off unsigned
In this use case 'unsigned value &= ~DEFINE;

As otherwise the right side is treated as signed, which annoyingly
triggers UBSan. The U_* defines are local versions of the public define,
only typecast to unsigned.

Reported-by: xmoezzz on github
Fixes #20753
Closes #20769
2026-03-03 16:02:50 +01:00
Daniel Stenberg
b4dba346cd
stop using the word 'just'
Everywhere. In documentation and code comments.

It is almost never a good word and almost always a filler that should be
avoided.

Closes #20793
2026-03-03 15:30:22 +01:00
Daniel Díaz
3aa63896ae
mbedtls: guard TLS 1.3 + session tickets usage inside ifdef
If TLS 1.3 is not supported, the call to
`mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets()` fails
during compilation:
```
curl-8.18.0/lib/vtls/mbedtls.c: In function 'mbed_connect_step1':
curl-8.18.0/lib/vtls/mbedtls.c:809:3: error: implicit declaration of function 'mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets' [-Werror=implicit-function-declaration]
   mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets(&backend->config,
   ^
curl-8.18.0/lib/vtls/mbedtls.c:809:3: warning: nested extern declaration of 'mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets' [-Wnested-externs]
```

Protect this call inside the `#ifdef` block by making sure that support
for TLS 1.3 is defined.

Closes #20789
2026-03-03 00:28:35 +01:00
Viktor Szakats
d557c06b52
build: drop unused snprintf() feature check on Windows
Follow-up to 64f28b8f88 #20765

Closes #20790
2026-03-02 22:40:29 +01:00
Viktor Szakats
30ec220a68
mprintf: silence clang-tidy readability-suspicious-call-argument
Follow-up to 64f28b8f88 #20765

Closes #20791
2026-03-02 22:21:21 +01:00
Viktor Szakats
64f28b8f88
curlx: add local snprintf() helper that always nul-terminates (Windows)
Make the helper use `vsnprintf()` internally on all supported Windows
toolchains (dropping `_snprintf()` and `snprintf()`), ensure to
nul-terminate. Omit the return value to avoid complexity.

Use the helper from `mprintf.c` / `out_double()`, from tests/server code
and the tests/server-specific build of `curlx_inet_ntop()`,
`curlx_strerror()` functions. In the single call (in tests) where the
returned length was used previously, determine it with `strlen()`.

Refs:
https://github.com/libssh2/libssh2/blob/libssh2-1.11.1/src/misc.c#L57-L79
https://learn.microsoft.com/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l
https://learn.microsoft.com/cpp/c-runtime-library/reference/vsnprintf-vsnprintf-vsnprintf-l-vsnwprintf-vsnwprintf-l

Assisted-by: Jay Satiro
Follow-up to fa8bd1cc09 #20761
Follow-up to 8ab468c8aa #15997

Closes #20765
2026-03-02 21:30:36 +01:00
Viktor Szakats
b83ade783d
multi: fix unreachable code compiler warning
```
lib/multi.c:305:5: error: code will never be executed [clang-diagnostic-unreachable-code]
  305 |     goto error;
      |     ^~~~~~~~~~
```

Cherry-picked from #20774

Closes #20788
2026-03-02 16:01:21 +01:00
Viktor Szakats
a5c6a4067a
clang-tidy: fix readability-suspicious-call-argument
Also:
- curlx/strerr: avoid a false positive by dropping an interim variable.
- enable this check.

Ref: #20627 (initial attempt)

Closes #20777
2026-03-02 15:28:25 +01:00
Viktor Szakats
7a77884a66
clang-tidy: enable clang-analyzer-* checks explicitly, fix fallout
v22.1.0 disabled them by default.

Fix fallout:
- http: check NULL to silence false positives in `HD_VAL()`.

Ref: https://releases.llvm.org/22.1.0/tools/clang/tools/extra/docs/ReleaseNotes.html#improvements-to-clang-tidy

Follow-up to da6fbb12a6 #20779
Follow-up to ce4db9c2ef #20751

Closes #20778
2026-03-02 14:01:09 +01:00
Viktor Szakats
da6fbb12a6
http1: fix potential NULL dereference in Curl_h1_req_parse_read()
Reported by clang-tidy v22 with `clang-analyzer-*` explicitly enabled:

```
lib/http1.c:89:31: error: Subtraction of a non-null pointer
 (from variable 'line_end') and a null pointer (via field 'line')
 results in undefined behavior [clang-analyzer-core.NullPointerArithm]
   89 |   parser->line_len = line_end - parser->line + 1;
      |                               ^
```
Ref: https://github.com/curl/curl/actions/runs/22534731241/job/65279952830?pr=20778#step:11:85

Ref: #20778

Closes #20779
2026-03-02 13:45:14 +01:00
Viktor Szakats
35bbb2e830
clang-tidy: fix issues found with build-fuzzing
- curl_sha512_256: add missing, drop redundant, parentheses.
- doh: drop redundant returns.
- url: add missing parentheses.
- vtls: fix unused const variables.
- tests/unit: fix missing header with clang-tidy and !threaded-resolver.
  Follow-up to 57ff2d6c91 #20106

Closes #20774
2026-03-01 00:04:18 +01:00
Viktor Szakats
bcc8144b89
clang-tidy: silence more minor issues found by v22
Also one found manually in lib/curl_sha512_256.c.

Follow-up to 7a08c5d820 #20762

Closes #20770
2026-02-28 13:16:54 +01:00
Florian Imdahl
006f561f6e
docs: some nitpicks
- replaced double spaces with single space where applicable
- replaced "favourite" with "favorite"
- added language identifiers to code blocks in markdown files
- added extra line after code blocks and after headings in markdown
  files

Cloes #20748
2026-02-27 23:05:37 +01:00
Viktor Szakats
7a08c5d820
ldap: silence clang-tidy v22 warning
Closes #20762
2026-02-27 15:57:48 +01:00
Viktor Szakats
fa8bd1cc09
mprintf: use _snprintf() when compiled with VS2013 and older
To support floats and doubles when using these old compilers.

Before this patch, these tests most likely failed with them:
```
FAIL 557: 'curl_mprintf() testing' printf, unittest
FAIL 566: 'HTTP GET with CURLINFO_CONTENT_LENGTH_DOWNLOAD and 0 bytes transfer' HTTP, HTTP GET
FAIL 599: 'HTTP GET with progress callback and redirects changing content sizes' HTTP, HTTP POST, chunked Transfer-Encoding
FAIL 1148: 'progress-bar' HTTP, progressbar
```

Also:
- mention `_snprintf()` in the `_CRT_SECURE_NO_WARNINGS` comment.

Follow-up to 7de35515d9 #20218

Closes #20761
2026-02-27 15:57:48 +01:00
Daniel Stenberg
61bcd1105a
cfilter: move a debug-only check into ifdef DEBUGBUILD
Pointed out by CodeSonar

Closes #20756
2026-02-27 08:21:15 +01:00
Daniel Stenberg
b48d02179a
ftp: remove two redundant assignments
Follow-up to 29bca12978

Pointed out by CodeSonar

Closes #20755
2026-02-27 08:10:11 +01:00
Viktor Szakats
b2076d3c2f
vquic: fix unused variable warning reported by clang-tidy
Silencing (seen in new GHA/Linux H3 v20 job):
```
lib/vquic/vquic.c:398:37: error: variable 'calls' set but not used [clang-diagnostic-unused-but-set-variable]
  398 |   size_t total_nread = 0, pkts = 0, calls = 0;
      |                                     ^
```

Cherry-picked from #20751

Closes #20752
2026-02-27 02:40:31 +01:00
Viktor Szakats
f76a54f890
clang-tidy: add missing and delete redundant parentheses
Reported by clang-tidy v22.1.0.

Ref: https://releases.llvm.org/22.1.0/tools/clang/tools/extra/docs/ReleaseNotes.html

Closes #20749
2026-02-27 01:03:41 +01:00
hamza
05d991a8c5
rtsp: fix assertion failure on zero-length RTP payload
Fixes #20735
Reported-by: David Korczynski
Closes #20744
2026-02-26 18:35:10 +01:00
Daniel Stenberg
6789eb0ff9
multi: avoid a theoretical 32-bit wrap
If Curl_uint32_tbl_count() at some future point actually can return
UINT_MAX, this fixes the math to not wrap.

Closes #20742
2026-02-26 17:14:50 +01:00
Viktor Szakats
b56e103d4d
build: do not include wolfSSL header in curl_setup.h
To fix building tests/server with cmake and both wolfSSL and OpenSSL
enabled (MultiSSL).

tests/server do not have libcurl dependency header paths setup because
it does not use libcurl. The code however includes `curl_setup.h`, which
tried including `wolfssl/version.h` before this patch to verify if the
wolfSSL coexist feature is available. Without a header path, it failed:
```
In file included from bld/tests/server/servers.c:3:
In file included from tests/server/first.h:40:
lib/curl_setup.h:737:12: fatal error: 'wolfssl/version.h' file not found
  737 | #  include <wolfssl/version.h>
      |            ^~~~~~~~~~~~~~~~~~~
1 error generated.
```
Ref: https://github.com/curl/curl/actions/runs/22410066319/job/64880787424#step:46:76

Fix by moving the include and version check to `vtls/wolfssl.c`.

Also: add an early version check to cmake.

Follow-up to 16f073ef49 #16973
Cherry-picked from #20720

Closes #20726
2026-02-26 01:36:16 +01:00
Viktor Szakats
3b9d8412c0
clang-tidy: add more missing parentheses in macro values
Reported when running `HeaderFilterRegex: '.*'` in CI.

Also replace an underscored symbol with a regular one in macro
definition.

Cherry-picked from #20720

Closes #20721
2026-02-25 15:43:23 +01:00
Viktor Szakats
af78b199b2
tidy-up: miscellaneous
- vms/curlmsg_vms.h: delete unused/commented code.
- vtls/schannel_verify: sort includes.
- typecheck-gcc.h: fix indent and alignment.
- lib/config-win32.h: drop idle `#undef`.
- spacecheck: check for stray empty lines before after curly braces.
- make literals more readable: 1048576 -> 1024 * 1024
- scope variables.
- use ISO date in a comment.
- drop redundant parentheses.
- drop empty comments.
- unfold lines.
- duplicate/stray spaces in comments.
- fix indent, whitespace, minor typos.

Closes #20690
2026-02-25 14:44:56 +01:00
Viktor Szakats
ac46392f44
clang-tidy: enable bugprone-signed-char-misuse, fix fallouts
Examples:
```
lib/vtls/openssl.c:2585:18: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
 2585 |       msg_type = *(const char *)buf;
lib/vtls/openssl.c:2593:18: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
 2593 |       msg_type = *(const char *)buf;
tests/server/mqttd.c:514:10: warning: comparison between 'signed char' and 'unsigned char' [bugprone-signed-char-misuse]
  514 |       if(passwd_flag == (char)(conn_flags & passwd_flag)) {
tests/server/tftpd.c:362:13: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
  362 |         c = test->rptr[0];
tests/server/tftpd.c:454:9: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
  454 |     c = *p++;                     /* pick up a character */
src/tool_urlglob.c:272:46: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
  272 |     pat->c.ascii.letter = pat->c.ascii.min = min_c;
src/tool_urlglob.c:273:24: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
  273 |     pat->c.ascii.max = max_c;
tests/libtest/cli_h2_pausing.c:164:23: warning: suspicious usage of 'sizeof()' on an expression of pointer type [bugprone-sizeof-expression]
  164 |   memset(&resolve, 0, sizeof(resolve));
tests/libtest/cli_upload_pausing.c:158:23: warning: suspicious usage of 'sizeof()' on an expression of pointer type [bugprone-sizeof-expression]
  158 |   memset(&resolve, 0, sizeof(resolve));
tests/libtest/first.c:86:15: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
   86 |     coptopt = arg[optpos];
```

Also:
- tests/server/mqttd: drop a redundant and a wrongly signed cast.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/signed-char-misuse.html

Closes #20654
2026-02-25 14:44:56 +01:00
Viktor Szakats
3e198f7586
build: fix building rare combinations
- http/2 + !headers
- gnutls + !verbose
- ssls-export + !verbose

Closes #20712
2026-02-24 20:49:06 +01:00
Viktor Szakats
102d4c8ba9
tidy-up: macro parentheses
Add missing and drop redundant parentheses.

Also: fix whitespace.

Ref: #20690

Closes #20710
2026-02-24 16:30:05 +01:00
Daniel Stenberg
704a0a3fa9
config-riscos.h: drop all undefs
They are superfluous

Closes #20711
2026-02-24 15:54:45 +01:00
Viktor Szakats
ba685ad5e5
openssl: fix potential NULL dereference when loading certs (Windows)
This could happen if the first cert to be loaded missed EKU (Enhanced
Key Usage) data, when using native CA on Windows.

Fix by skipping certs without Enhanced Key Usage data.

Detected by clang-tidy:
```
lib/vtls/openssl.c:2922:15: warning: Access to field 'cUsageIdentifier'
 results in a dereference of a null pointer (loaded from variable
 'enhkey_usage') [clang-analyzer-core.NullDereference]
 2922 |           if(!enhkey_usage->cUsageIdentifier) {
      |               ^
```

Refs:
https://learn.microsoft.com/windows/win32/secgloss/e-gly
https://learn.microsoft.com/windows/win32/api/wincrypt/nf-wincrypt-certgetenhancedkeyusage
https://gitlab.winehq.org/wine/wine/-/blob/wine-11.2/dlls/crypt32/cert.c?ref_type=tags#L3061-3164

Assisted-by: Stefan Eissing

Closes #20634
2026-02-24 12:34:19 +01:00
Daniel Stenberg
7981594df5
mbedtls: split mbed_connect_step1 into sub functions
Increase readability. Reduce complexity.

Closes #20689
2026-02-24 11:19:20 +01:00
Daniel Stenberg
956e1ae84f
setopt: refuse blobs with zero length
A blob must have a length or it will not be accepted. By enforcing the
check here, TLS backend code can rely on the fact that the length is
always non-zero from this point.

Reported-by: aisle-research-bot
URL: https://github.com/curl/curl/pull/20689#pullrequestreview-3846390367
Closes #20705
2026-02-24 11:18:12 +01:00
Viktor Szakats
453470fab1
spacecheck: double spaces in folded strings, fix fallouts
Closes #20695
2026-02-24 00:48:12 +01:00
Viktor Szakats
65262be0ab
clang-tidy: enable readability-math-missing-parentheses, adjust code
No functional changes.

Also:
- md4, md5: drop redundant parentheses from macro values.

Closes #20691
2026-02-23 18:57:40 +01:00
Daniel Stenberg
29bca12978
ftp: split ftp_state_use_port into sub functions
For readability and reduced complexity.

Fixed a bug when FTPPORT specifies an IPv6-address only, without brackets.

Closes #20685
2026-02-23 17:22:26 +01:00
Viktor Szakats
f1cee1f18a
clang-tidy: add arg names to prototypes where missing (cont.)
Detected by `readability-named-parameter` with `HeaderFilterRegex: '.*'`,
or `CURL_CLANG_TIDYFLAGS='--header-filter=.*'`. Seen on Windows.

Follow-up to e8415ad3c7 #20657
Follow-up to c878160e9c #20624

Closes #20693
2026-02-23 17:03:01 +01:00
Daniel Stenberg
e9786038d6
setopt: make setopt_copypostfields a separate function
Closes #20688
2026-02-23 16:45:37 +01:00
Viktor Szakats
3058ed3df8
lib: use lib source directory as base include path
Backtrack on previous change that aimed to solve the wrong `share.h`
being included. It turns out it did not fix this issue. At the same time
it introduced relative header filenames and the need to include the same
headers differently depending on the source files' location, reducing
readability and editability.

Replace this method by re-adding curl's lib source directory to the
header path and addressing headers by the their full, relative name to
that base directory. Aligning with this method already used in src and
tests.

With these advantages:
- makes includes easier to read, recognize, grep, sort, write, and copy
  between sources,
- syncs the way these headers are included across curl components,
- avoids the ambiguity between system `schannel.h`, `rustls.h` vs.
  local headers using the same names in `lib/vtls`,
- silences clang-tidy `readability-duplicate-include` checker, which
  detects the above issue,
  Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/duplicate-include.html
- possibly silences TIOBE coding standard warnings:
  `6.10.2.a: Don't use relative paths in #include statements.`
- long shot: it works well with concatenated test sources, for
  clang-tidy-friendly custom unity builds. Ref: #20667

Slight downside: it's not enforced.

If there happens to be a collision between a local `lib/*.h` header and
a system one, the solution is to rename (possibly with its `.c`
counterpart) into the `curl_` namespace. This is also the method used by
curl in the past.

Also:
- curlx/inet_pton: reduce scope of an include.
- toolx/tool_time: apply this to an include, and update VS project
  files accordingly. Also dropping unnecessary lib/curlx header path.
- clang-tidy: enable `readability-duplicate-include`.

Follow-up to 3887069c66 #19676
Follow-up to 625f2c1644 #16991 #16949

Closes #20623
2026-02-23 16:00:42 +01:00
Viktor Szakats
d6d8a1a15a
cmake: always build curlu and curltool test libs in unity mode
To speed up building/running tests by default (e.g. via `testdeps` or
`tests` targets.)

It reduces build commands to 21 (from 239) for a test build.

In CI, it affects build test step times as below:
- GHA/linux: aws-lc
  12s https://github.com/curl/curl/actions/runs/22279958343/job/64448913413 ->
  6s https://github.com/curl/curl/actions/runs/22282767915/job/64455970302
- GHA/linux: Fil-C
  39s https://github.com/curl/curl/actions/runs/22279958343/job/64448913430 ->
  37s https://github.com/curl/curl/actions/runs/22282767915/job/64455970352
- GHA/non-native: FreeBSD Intel
  22s https://github.com/curl/curl/actions/runs/22279958335/job/64448913514 ->
  15s https://github.com/curl/curl/actions/runs/22282767899/job/64455969960
- GHA/windows: dl-mingw 6.4.0
  23s https://github.com/curl/curl/actions/runs/22279958334/job/64448917225 ->
  9s https://github.com/curl/curl/actions/runs/22282767922/job/64455975006

Follow-up to fff9905bcf #20670

Closes #20677
2026-02-23 13:56:59 +01:00
Daniel Stenberg
3877db7bcf
openssl: fix compiler warning with OpenSSL master
vtls/openssl.c:469:15: error: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

X509_get_X509_PUBKEY() now returns a const pointer - but only on OpenSSL
3, we must keep the non-const version for all forks.

Closes #20681
2026-02-23 10:23:57 +01:00
Viktor Szakats
e8415ad3c7
clang-tidy: add arg names to prototypes where missing
Detected by `readability-named-parameter` with `HeaderFilterRegex: '.*'`,
or `CURL_CLANG_TIDYFLAGS='--header-filter=.*'`.

Follow-up to c878160e9c #20624

Closes #20657
2026-02-23 01:00:47 +01:00
Viktor Szakats
fff9905bcf
cmake: force-disable unity for clang-tidied build targets only
Instead of globally disabling unity for all targets when clang-tidy is
enabled.

After this patch `CMAKE_UNITY_BUILD=ON` is honored for:
- static libcurl when building both static and shared separately.
- libcurlu and libcurltool internal libraries when building the test
  target.

While keeping unity disabled for the libcurl build pass running
clang-tidy, and the curl tool, also running clang-tidy.

To make clang-tidy-enabled builds finish faster when unity mode is
enabled, yet performs the same clang-tidy checks as before this patch.

Effect on:
- GHA/macos: core build: same, buils tests 5-12 seconds faster,
  with steps going down from 259 to 25.

  52s: https://github.com/curl/curl/actions/runs/22279958340/job/64448913325 ->
  47s: https://github.com/curl/curl/actions/runs/22279873606/job/64448710743

- GHA/windows (not enabled): it'd save about 1 minute, bringing total
  time barely below 10m, still one of the slowest jobs overall.
  (#20667 is trying a way for 4x speed-up (with a drawback)).

  5m21s: https://github.com/curl/curl/actions/runs/22222907068/job/64284556852 ->
  4m26s: https://github.com/curl/curl/actions/runs/22281033369/job/64451601548

Closes #20670
2026-02-22 19:16:31 +01:00
Daniel Stenberg
84112673a0
socks_sspi: split Curl_SOCKS5_gssapi_negotiate into sub functions
Create and use socks5_sspi_setup(), socks5_sspi_loop() and
socks5_sspi_encryption(). Reduces complexity.

Closes #20581
2026-02-22 16:17:49 +01:00
Viktor Szakats
898ec9f2fb
cmake: limit clang-tidy to the shared libcurl if static is also built
On platforms that require building static and shared libcurl separately,
after this change clang-tidy is only run on one of them, to reduce build
time by avoiding the double-work. From a clang-tidy standpoint, static
and shared libs are identical.

Except `dllmain.c` on Windows, which is only present in shared. To keep
running it through clang-tidy, prefer the shared library for clang-tidy.

Closes #20675
2026-02-22 16:05:10 +01:00
Viktor Szakats
e009beab89
clang-tidy: add missing parentheses to debug macro arguments
Follow-up to 139307865a #20647

Closes #20674
2026-02-22 13:51:02 +01:00
Viktor Szakats
139307865a
clang-tidy: check bugprone-macro-parentheses, fix fallouts
Also:
- lib/parsedate: avoid relying on side-effect of missing parentheses.
- lib/http: drop redundant parentheses.
- fix cases in headers missed by clang-tidy.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/macro-parentheses.html

Closes #20647
2026-02-22 00:58:04 +01:00
Daniel Stenberg
f1a39f221d
url: fix copy and paste url_match_auth_nego mistake
Follow-up to 34fa034
Reported-by: dahmono on github
Closes #20662
2026-02-21 18:37:31 +01:00
Viktor Szakats
a0244c536e
inet_pton: scope an include
Closes #20661
2026-02-21 15:06:58 +01:00
Viktor Szakats
b35e58b24c
openssl: fix potential OOB read in debug/verbose logging
Reported-by: aisle-research-bot
Bug: https://github.com/curl/curl/pull/20654#discussion_r2834860711

Closes #20656
2026-02-21 15:06:58 +01:00
Viktor Szakats
020f48d00c
clang-tidy: drop some redundant conditions reported by misc-redundant-expression
Not enforced due to false positives, and because in cases a redundant
expression (e.g. encapsulated in a macro) may be preferred.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/misc/redundant-expression.html

Closes #20644
2026-02-21 15:06:58 +01:00
Stefan Eissing
078b3031ea
easy: reset pausing when resetting request
When the easy handle's request is reset, this needs to also reset
any pausing/ratelimit state.

Reported-by: Natris on github
Fixes #20641
Closes #20643
2026-02-21 14:56:06 +01:00
Christian Schmitz
d19c9e4e63
request.h: rename parameter 'buf' to 'req' in Curl_req_send
Someone renamed the parameter, so we need to rename the documentation.

Closes #20660
2026-02-21 14:55:05 +01:00
Viktor Szakats
977ac0c06c
clang-tidy: check misc-header-include-cycle, fix in internal headers
Also opt-out `curl/curl.h` because it includes `curl/mprintf.h`, which
in turn includes `curl/curl.h` for `CURL_EXTERN`. Not changeable in
public headers to remain compatible. (Somehow only triggered for
examples.)

Ref: https://clang.llvm.org/extra/clang-tidy/checks/misc/header-include-cycle.html

Closes #20645
2026-02-20 17:33:02 +01:00
Viktor Szakats
4b4637a445
build: disable typecheck via the command-line instead of curl_config.h
To make it apply to examples. This in turn makes analyzers run quicker
and with fewer false positives.

It's a special disable option, having its effect via `curl/curl.h`.

Bug: https://github.com/curl/curl/pull/20649#issuecomment-3934885021
Follow-up to 9e6f1c5efb #19637

Closes #20650
2026-02-20 16:32:37 +01:00
Viktor Szakats
dd82205bb2
memdebug: include backtrace.h as system header
Closes #20642
2026-02-20 16:32:37 +01:00
Viktor Szakats
4042e7d9d8
clang-tidy: work around clang-tidy <=20 false positive (Windows)
clang-tidy <= v20 (as seen between 18.1.3 and 20.1.2) report
`readability-uppercase-literal-suffix` originating from mingw-w64 system
header `_mingw_mac.h` via `define __MSABI_LONG(x) x ## l`

Triggered by `SOCKENOMEM` (e.g. in tests/server/sockfilt.c):
```
warning: integer literal has suffix 'l', which is not uppercase [readability-uppercase-literal-suffix]
```

Work around by replacing Windows macro `WSA_NOT_ENOUGH_MEMORY`
with its literal value.

Bug: https://github.com/curl/curl/pull/20631#issuecomment-3930619868
Follow-up to c07c3cac74 #20629
Cherry-picked from #20631

Closes #20638
2026-02-20 12:08:52 +01:00
Viktor Szakats
8712fac111
clang-tidy: drop redundant casts
Found via `readability-redundant-casting`. Prone to false positives, not
enabled.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-casting.html

Closes #20630
2026-02-19 15:27:17 +01:00
Viktor Szakats
c07c3cac74
clang-tidy: enable and fix readability-uppercase-literal-suffix
Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/uppercase-literal-suffix.html

Closes #20629
2026-02-19 15:27:17 +01:00
Viktor Szakats
3cdc167425
clang-tidy: check readability-redundant-preprocessor, fix fallouts
Also:
- cipher_suite: merge `USE_MBEDTLS` `#if` blocks.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-preprocessor.html

Closes #20628
2026-02-19 15:27:17 +01:00
Viktor Szakats
c878160e9c
clang-tidy: sync argument names in prototype and definition
Discovered with clang-tidy checker
`readability-inconsistent-declaration-parameter-name`.

Also:
- do not enforce the above because of inconsistencies still present
  between public API prototypes and definitions. (Also betwen man page
  protos, and man page examples, and other parts of the code, e.g.
  `easy` vs `curl` vs `d` vs `handle`) Perhaps subject for a future
  effort:
  https://github.com/curl/curl/actions/runs/22166472728/job/64094691653
- enable and fix `readability-named-parameter` where missing.

Refs:
https://clang.llvm.org/extra/clang-tidy/checks/readability/inconsistent-declaration-parameter-name.html
https://clang.llvm.org/extra/clang-tidy/checks/readability/named-parameter.html

Closes #20624
2026-02-19 12:44:37 +01:00
Viktor Szakats
4497dbd9ac
clang-tidy: fixes and improvements
Fix bigger and smaller kinks in how clang-tidy is configured and used.
Sync behavior more between autotools and cmake, lib/src and tests. Bump
clang-tidy minimum version and prepare logic to allow using clang-tidy
to a fuller extent.

- move clang-tidy settings from builds to a new `.clang-tidy.yml`.
  To make it easy to see and edit checks at one place. Also to allow
  using the `--checks=` option internally to silence tests-specific
  checks. (clang-tidy does not support multiple `--check=` options via
  the command-line.)
  Use explicit `--config-file=` option to point to the configuration.
- .clang-tidy.yml: link to documentation.
- suppress `clang-diagnostic-nullability-extension` due to a false
  positive in libtests with `CURL_WERROR=ON` and `PICKY_COMPILER=OFF`.
- .clang-tidy.yml: enable `portability-*`, `misc-const-correctness`.
- drop `--quiet` clang-tidy option by default to make its working a bit
  more transparent. The extra output is minimial.
- consistently use double-dashes in clang-tidy command-line options.
  Supported by clang-tidy 9.0.0+ (2019-09-19). Before this patch single
  and double were used arbitrarily.
- src/tool_parsecfg: silence false positive `clang-analyzer-unix.Stream`.
  Seen with clang 18 + clang-tidy 19 and 20 (only with autotools.)
- INTERNALS: require clang-tidy 14.0.0+. For the `--config-file` option.
- INTERNALS: recommend clang-tidy 19.1.0+, to avoid bogus
  `clang-analyzer-valist.Uninitialized` warnings. (bug details below)

autotools:

- allow configuring the clang-tidy tool via `CLANG_TIDY` env.
  Also to use in GHA to point to a suffixed clang-tody tool.
- fix to pass CFLAGS to lib, src sources.
  (keep omitting them when using a non-clang compiler.)
- fix to pass `--warnings-as-errors=*` in quotes to avoid globbing.

cmake:

- fix to not pass an empty `-I` to clang-tidy.
- fix to pass CFLAGS (picky warnings) to clang-tidy for test sources.
  (keep omitting them when using a non-clang compiler.)
- fix to disable `clang-diagnostic-unused-function` for test sources.
  (tests have static entry points, which trigger this check when
  checking them as individidual sources.)
- fix forwarding `CURL_CLANG_TIDYFLAGS` to clang-tidy.
- force disable picky warnings when running clang-tidy with a non-clang
  compiler. To not pass these flags when checking lib and src.

CI:

- GHA/linux: avoid clang-tidy bug by upgrading to v19, and drop the
  workaround.
- GHA/linux: switch to clang from gcc in the clang-tidy job. Using gcc
  doesn't allow passing CFLAGS to clang-tidy, making it less effective.
  (My guess this was one factor contributing to this job often missing
  to find certain issues compared to GHA/macos.)

I recomment using clang-tidy with a clang compiler, preferably the same
version or one that's compatible. Other cases are best effort, and may
fail if a C flag is passed to clang-tidy that it does not understand.
Picky warnings are mostly omitted when using a non-clang compiler,
reducing its usefulness.

Details and reproducer for the v18 (and earlier) clang-tidy bug,
previously affecting the GHA/linux job:

clang-tidy <=18 emits false warnings way when passing multiple C sources
at once (as done with autotools):

```sh
cat > src1.c <<EOF
#include <string.h>
static void dummy(void *p) { memcmp(p, p, 0); }
EOF

cat > src2.c <<EOF
#include <stdarg.h>
void vafunc(int option, ...)
{
  va_list param;
  va_start(param, option);
  if(option)
    (void)va_arg(param, int);
  va_end(param);
}
EOF

/opt/homebrew/opt/llvm@18/bin/clang-tidy --checks=clang-analyzer-valist.Uninitialized src1.c src2.c

# src2.c:7:11: warning: va_arg() is called on an uninitialized va_list [clang-analyzer-valist.Uninitialized]
```

Follow-up to e86542038d #17047

Closes #20605
2026-02-19 00:02:11 +01:00
Viktor Szakats
5fa5cb3825
build: fix -Wunused-macros warnings, and related tidy-ups
- fix internal macro `AN_APPLE_OS` reused between sources without
  resetting it. It may potentially have left the system sha256
  function unused.
- fix to define `WOLFSSL_OPTIONS_IGNORE_SYS` so that it always applies
  to wolfSSL headers, also during feature detection.
- md4, md5, sha256: simplify fallback logic.
- delete 20+ unused macros.
- scope or move macros to avoid `-Wunused-macros` warnings.
- examples: delete unused code.

The warning detects macros defined but not used within the same C
source. It does not warn for macros defined in headers. It also works
with unity builds, but to a lesser extent.

Closes #20593
2026-02-19 00:00:48 +01:00
Viktor Szakats
633ec719d5
curl_ntlm_core: merge two #if blocks
Cherry-picked from #20593

Closes #20620
2026-02-18 22:04:45 +01:00
Viktor Szakats
dc08922a61
openssl: disable local keylog feature if built-in upstream
Reported-by: Paul Howarth
Fixes #20611

Closes #20614
2026-02-18 12:04:23 +01:00
Stefan Eissing
f1c9d5e484
easy: reset errorbuf on eyeballing success
Any failf() that fill the errorbuf need to be forgotten once happy
eyeballing finds a succssful winner. Because the errorbuf, once set, is
not overwritten with future error information.

Adds test_05_05 to verify.

Reported-by: Tim Friedrich Brüggemann
Fixes #20608

Closes #20613
2026-02-18 12:04:23 +01:00
Viktor Szakats
8fb87f5a4a
lib: delete unused local includes
Filtered from `clang-tidy` `misc-include-cleaner` hits.

Also:
- pingping: scope includes.
- doh: say the reason for an include.

Closes #20607
2026-02-16 21:13:43 +01:00
Viktor Szakats
1eec8b8d03
mprintf: rename internal enum to avoid collision with AmigaOS symbol
Also:
- drop AmigaOS workaround.

Closes #20584
2026-02-15 22:54:31 +01:00
Viktor Szakats
9e1e5ea67c
curl_setup.h: update/expand OPENSSL_SUPPRESS_DEPRECATED comment
Document functions/features requiring it.

Follow-up to cab040248d #10543
Cherry-picked from #20593

Closes #20600
2026-02-15 12:48:46 +01:00
Viktor Szakats
d445f2d930
lib: skip compiling code with features disabled
In non-SSL, non-SSH, non-H3, non-AppleSecTrust builds.

Also:
- drop unused internal macro `SSL_SYSTEM_VERIFIER`.

Closes #20587
2026-02-13 15:48:23 +01:00
Daniel Stenberg
207ab758f5
ws/tftp: include header file even when protocol disabled
As the scheme details are still needed. clang 21 warned for this in HTTP-only
builds.

Reported-by: Marcel Raad
URL: https://curl.se/mail/lib-2026-02/0008.html
Closes #20568
2026-02-12 22:47:53 +01:00
Daniel Stenberg
36dc50b7e3
smb: include arpa/inet.h for NonStop
Reported-by: Randall S. Becker
URL: https://curl.se/mail/lib-2026-02/0010.html
Closes #20579
2026-02-12 22:46:56 +01:00
Daniel Stenberg
10bb489b22
schannel: refactor: reduce variable scopes, fix comment, fix indent
Refactor and simplify the Schannel code, primarily by reducing
duplicated buffer-management and credential-setup logic.

- split client certificate selection into get_client_cert() and SSPI
  credential acquisition into acquire_sspi_handle()
- introduce a struct sbuffer for encrypted/decrypted buffering
- Add ensure_encoding_size() and ensure_decoding_size() helpers to
  centralize buffer growth/realloc decisions
- Tighten variable scopes and tidy indentation/logging in the handshake
  and receive/decrypt loops.
- Update comments and adjusts some receive error-condition handling to
  better preserve buffered-data behavior.

Closes #20569
2026-02-12 22:34:58 +01:00
Daniel Stenberg
df6f3ae60a
multi: split multi_runsingle into sub functions
To reduce complexity.

- is_finished() checks if the individual transfer is done

- handle_completed() is the logic that runs for a completed
  transfer

Closes #20573
2026-02-12 22:34:23 +01:00
Viktor Szakats
5edd79aa93
cmake: add CURL_PATCHSTAMP configuration variable, test in CI
Also:
- INSTALL-CMAKE.md: alpha sort.

Closes #20576
2026-02-12 17:29:22 +01:00
Viktor Szakats
516a0cd382
cmake: add BORINGSSL_VERSION configuration variable, test in CI
To simplify setting BoringSSL version, using:
`-DBORINGSSL_VERSION=0.20260211.0`
or
`-DBORINGSSL_VERSION=${boringssl_version}`

Previously it could be set via C flags, using complicated shell quotes:
`-DCMAKE_C_FLAGS="-DCURL_BORINGSSL_VERSION=\\\"${boringssl_version}\\\""`
(the C flags method remains, also for autotools)

It'd be nice if BoringSSL published its version not just via
`MODULE.bazel` in its source tree, but from its public headers, to make
these workarounds unnecessary.

Also:
- GHA/http3-linux: test both options.

Closes #20571
2026-02-12 16:29:49 +01:00
Viktor Szakats
61df5f466c
tidy-up: miscellaneous
- curl_ntlm_core, smtp, schannel: fix comments.
- curl_setup.h: fix to undef before define.
- tool_doswin, server/sockfilt: reduce variables scopes.
- tool_doswin: drop an interim variable.
- windows: replace `SOCKET_ERROR` with `0` to align with rest of code.
- libssh2: rename variable to align with rest of code.
- gtls, unit1398: use `#if 0`.
- curl_trc.h, curlx/inet_ntop.h: add missing parentheses in macro
  expressions.
- ldap.c: set empty macro to `do {} while(0)`.
- examples/crawler: rename a non-CURLcode `result` variable.
- CURLINFO_TLS_SESSION: drop stray colon.
- add `const` to casts where missing.
- drop unnecessary parentheses.
- fix indent.
- quote style.
- comment style.
- whitespace, newlines, fold/unfold.

Closes #20554
2026-02-12 14:52:16 +01:00
Viktor Szakats
2a92c39a21
windows: tidy up wincrypt.h / BoringSSL/AWS-LC coexist workaround
- openssl: move and expand explanatory comment.

- openssl: drop duplicate workaround.

- schannel: drop workaround. Unnecessary, because OpenSSL headers are
  not included in or after schannel code.

- schannel: drop explicit `wincrypt.h` include. It's indirectly
  included by system `<schannel.h>`.

- ldap: drop explicit `wincrypt.h` include.
  It isn't used there, and also not required for the workaround.
  `winldap.h` keeps including it indirectly.

Tested with BoringSSL and AWS-LC (MultiSSL with Schannel), also LDAP
enabled, and H3, unity and non-unity, and all tested cases build fine.

In lib in general, the point is to have the `#undef`s between the first
`wincrypt.h` include [1] and the first OpenSSL include [2], within a
single compilation unit. For non-unity builds the only such source is
`openssl.c`. For unity ones, depending on batch size, in theory we
should `#undef` after each `wincrypt.h` include. In practice this is
overkill and most cases are covered by `#undef`-fing _first_ in
`vtls/openssl.c`, and `#undef` in `ldap.c`. It's not impossible that we
need to add more undefs after further `wincrypt.h` includes to cover so
far undiscovered build cases [3]. Though I could not find more with the
current sources and source order.

It's also an option to include OpenSSL first, then `wincrypt.h`, as
done in libtests, but for lib and `vtls/openssl.c` it's more practical
to do the opposite.

[1] can be indirect, e.g. via `iphlpapi.h`, `schannel.h`, `winldap.h`.

[2] in
- BoringSSL/AWS-LC: any include (due to `openssl/base.h`).
  Original fix removed by BoringSSL in year
  [2014](ded93581f1 (diff-878093ea6426091505b4c49c59b78924f42859af0eb4ce39b8089bda9577e013)).
- OpenSSL: `openssl/ssl.h`, `openssl/x509v3.h`, and some more affected,
  and including `openssl/ossl_typ.h` does the `#undef` automatically.
  Since [3.1.0+](fbb9a1f997)
  each inclusion does the `#undef`, in 3.0.x (and earlier) only
  the first inclusion did. Initially fixed in
  [0.9.6d](1955b87423)
- LibreSSL [2.3.0+](0fa826d34f):
  not affected, though to suppress another warning 3.8.2+ and
  a [define](e7fe6caab2)
  is necessary.

[3] `lib/Makefile.inc` defines the order of unity sources.

For libtests, the case is simpler: There is always one compilation unit,
with a fixed order, and at the moment `cli_hx_download.c` is including
OpenSSL first, then wincrypt, and in this order they don't bother each
other. Also, at the moment `lib758.c` is the only other OpenSSL header
user, but it's compiled after `cli_hx_download.c` so the include is
skipped there. We may need to revisit this if either header gets
included before it.

All this said it'd be nice if BoringSSL/AWS-LC restored the built-in
workaround to behave like LibreSSL and OpenSSL and not require local
workarounds like these.

Ref: https://github.com/curl/curl/pull/20556#issuecomment-3888425644

Follow-up to 4c46c829f5 #9110
Follow-up to fbe07c6829 #5669 #5857

Closes #20567
2026-02-12 14:31:39 +01:00
Viktor Szakats
c220674ac4
windows: tidy up includes, macros, document dependencies
- define `SECURITY_WIN32` globally in `curl_setup.h`.
  To make sure it applies to all includes.

- document which Windows headers require `SECURITY_WIN32`.

- stop suppressing MSVC warning:
  `C4201 is: nonstandard extension used : nameless struct/union`
  The warning is no longer seen in supported build envs with the current
  codebase.
  Follow-up to 8beff43559 #8419

- document why `SCHANNEL_USE_BLACKLISTS` is needed.

- just define `SCHANNEL_USE_BLACKLISTS`, drop the unnecessary value `1`.

- stop defining unused `SCH_CRED_MAX_SUPPORTED*` fallback macros.
  Follow-up to 8beff43559 #8419

- document why `subauth.h` is included (where missing).

- move and de-dupe `subauth.h` include into `curl_setup.h`, limit to
  Schannel builds.

- stop include `schnlsp.h`. It is a 1-to-1 compatibility wrapper for
  `schannel.h`.

- curl_sspi.h: clarify comment about `SP_NAME_` macros.
  They are local macros, their SDK names are different and curl does not
  use them.

- curl_sspi.h: drop superfluous includes `security.h` and `rpc.h`.

Cherry-picked from #20556

Closes #20564
2026-02-11 16:15:11 +01:00
Viktor Szakats
982ab7b53f
build: check MSG_NOSIGNAL directly, drop detection and interim macro
Drop detecting it at configure time, along with the interim macro
`HAVE_MSG_NOSIGNAL`. There is no longer a reason for this workaround,
and allows to save the work at configure time and simplify.

Also say in a comment that `sys/socket.h` is defining this macro.

Follow-up to 77b3bc239d

Closes #20559
2026-02-11 14:51:08 +01:00
Viktor Szakats
c05cd2a10e
curl_setup.h: merge back single-use internal header curl_setup_once.h
Originally split in 2006, but the issues cited are no longer present in
current code. As of now both `curl_setup.h` and `curl_setup_once.h` are
included once per compiler invocation, without recursion. The latter is
a sub-header of the former with no clear distinction in their contents.

Merge them to avoid having to decide where to put new global PP logic.
Also to make it easier to overview what gets defined/included globally
and in what order. (Perhaps even allowing some tidying up here.)

Follow-up to 77b3bc239d

Closes #20555
2026-02-11 14:26:30 +01:00
Daniel Stenberg
ee3a4dff1a
http_aws_sigv4: fix query normalization of %2b
Reported-by: Nuno Goncalves
Fixes #20543
Closes #20550
2026-02-10 07:52:18 +01:00
Viktor Szakats
5c250e2421
gss: exclude verbose error logic from non-verbose builds
Closes #20551
2026-02-10 02:34:33 +01:00
Jay Satiro
b844c1a075 vtls: use ALPN http/1.0 & http/1.1 for HTTP/1.0 requests
- For compatibility reasons send both ALPN ids http/1.0 and http/1.1 for
  HTTP/1.0 requests.

Prior to this change for compatibility reasons curl would send ALPN
http/1.1 for HTTP/1.0 requests, since some servers do not recognize
ALPN http/1.0. However some servers may recognize only ALPN http/1.0 for
HTTP/1.0 requests. Therefore curl now sends both.

Reported-by: programmerlexi@users.noreply.github.com

Fixes https://github.com/curl/curl/issues/20487
Closes https://github.com/curl/curl/pull/20533
2026-02-09 12:15:35 -05:00
Daniel Stenberg
950c7bb174
digest: escape double quotes and backslashes in realm and nonce
change test 907 to use quote in realm to verify

Fixes #20482
Reported-by: cooldadpresident on github
Closes #20545
2026-02-09 08:50:32 +01:00
Viktor Szakats
cdfc8dc7ad
build: tidy up and simplify setmode() detection and use
- move macro to `curl_setup.h` (from curlx), and rename.
  It's required by src, test servers, libtests. Also used by unit/tunit,
  (which is fixable but this patch doesn't touch it.)
- special-case it for Windows/Cygwin/MS-DOS.
- build: drop `setmode()`/`_setmode()` detection.
  This also avoids detecting the different `setmode()` on BSDs,
  and a lot of complexity and overhead.
- use `CURL_O_BINARY`.

Follow-up to 250d613763 #15787
Follow-up to 5e70566094 #15169

Closes #20539
2026-02-08 15:47:47 +01:00
Viktor Szakats
2c0019b085
curl_setup.h: drop extra header guard for internal include
The included local header starts with this same guard. The original
commit added it for fixing VMS builds along with many other changes, but
without mention of this specific one in the commit message.

`curl_setup.h` is included once, which includes `curl_setup_once.h`
once, even if the latter wouldn't have it's own guard.

Ref: 25f351424b

Closes #20544
2026-02-08 15:47:47 +01:00
Viktor Szakats
bb56f325a4
curl_get_line: drop single-use macro
Follow-up to 769ccb4d42 #19140

Closes #20542
2026-02-08 15:47:47 +01:00
Daniel Stenberg
aa0be708b9
url.c: restore mistaken comment change
Follow-up to d7a9f1ab15

Closes #20540
2026-02-07 23:26:57 +01:00
Daniel Stenberg
34fa034d9a
url: fix reuse of connections using HTTP Negotiate
Assume Negotiate means connection-based

Reported-by: Zhicheng Chen
Closes #20534
2026-02-07 22:16:53 +01:00
Viktor Szakats
85de995208
tidy-up: move literals to right-side of if expressions (where missing)
Closes #20535
2026-02-07 16:41:51 +01:00
Juan Belon
12a1be509e
curl_setup_once: allow CURL_DEBUGASSERT for customization
Closes #19744
2026-02-05 17:40:46 +01:00
Stefan Eissing
d7a9f1ab15
url.c: code/comment cleanup around conn creation
Several comments were outdated and parameters to create_conn() and
ConnectionExists() were not needed. Give functions better names and
consistently use terms `needle` and `conn`.

No functional change.

Closes #20464
2026-02-05 17:21:53 +01:00
Viktor Szakats
4b3af7fb67
lib: disable websockets early if no http
To prevent inconsistent `CURL_DISABLE_WEBSOCKETS` states between source
files.

Follow-up to 8edc0338f3 #20351

Closes #20526
2026-02-05 13:12:10 +01:00
Viktor Szakats
f659b82c2a
build: make HTTP_ONLY build options also disable websockets
Closes #20525
2026-02-05 13:12:10 +01:00
Viktor Szakats
462244447e
build: use native file open flags in Windows-specific code
To comply with official documentation. Also to make code compile with
`NO_OLDNAMES` (mingw-w64) or `_CRT_DECLARE_NONSTDC_NAMES=0` (MSVC) set.

Ref: #15652

Closes #20516
2026-02-04 15:59:35 +01:00
Daniel Stenberg
94349aa932
mqtt: verify Remaining Length for CONNACK and PUBACK
Verified in test 1132

Closes #20513
2026-02-04 15:43:13 +01:00
Viktor Szakats
443a539fcf
build: move curl stat struct type to the curlx namespace
To match surrounding curlx symbols and functions.

Follow-up to a84b041281 #20496

Closes #20508
2026-02-04 02:07:16 +01:00
Daniel Stenberg
fdca2e0fd3
imap: add a check for Curl_meta_get()
It should not return NULL, but if it does we need to bail out. Like we
do elsewhere.a

Found by CodeSonar.
Closes #20510
2026-02-03 23:24:06 +01:00
Stefan Eissing
2d4efbb9b3 multi: update timer unconditionally in multi_remove_handle
When removing an easy handle from a multi, there was an optimization
to update the timer only when the removed handle had any timers.

With the introduction of the "dirty" bitset, easy handles can now cause
a timeout of 0 to be set without having anything in their timer list.
Removing such a handle needs to update the timer now always, so that
it may get cleared when there is nothing more to wait for.

The previous "not clearing a 0 timer" should not have any effect on
application's logic. Without clearing, the timer will fire and then
adjust itself to the proper value. But it would cause one more timer
fire than necessary.

Reported-by: Jan Macku

Fixes https://github.com/curl/curl/issues/20498
Closes https://github.com/curl/curl/pull/20502
2026-02-03 16:24:39 -05:00
Viktor Szakats
0590753a3c
build: require POSIX strdup()
Stop detecting this function and drop the local fallback.

Let us know if this update is causing an issue.

Notes:
- on Windows `_strdup()` is required instead.
- `strdup()/_strdup()` were required before this patch to build one of
  the examples: `block_ip`.
- `strdup()/_strdup()` were required in 8.18.0 and earlier to build
  tests.

Closes #20505
2026-02-03 17:50:18 +01:00
Viktor Szakats
710d5a28fb
fopen.h: simplify curl memory macro mappings
Closes #20506
2026-02-03 15:13:37 +01:00
Viktor Szakats
5bdbad87c5
curlx: drop unused curlx_saferealloc()
Unused since 67ae101666 #19949

Closes #20504
2026-02-03 15:13:37 +01:00
Viktor Szakats
31a4f415af
build: tidy up and dedupe strdup functions
- de-dupe lib/src strdup/memdup functions into curlx.
- introduce `CURLX_STRDUP_LOW()` for mapping `strdup()`, and to do it at
  one place within the code, in `curl_setup.h`.
- tests/server: use `curlx_strdup()`. (Also to fix building without
  a system `strdup()`.)
- curlx/curlx.h: shorten and tidy up.
- adjust Windows build path to not need `HAVE_STRDUP`.
- build: stop detecting `HAVE_STRDUP` on Windows.

Closes #20497
2026-02-03 14:02:30 +01:00
Viktor Szakats
e39650c984
curl_setup.h: simplify curl memory macro mappings
Full argument listing is redundant for `curl`-prefixed internal macros.

Closes #20499
2026-02-03 10:54:42 +01:00
Stefan Eissing
ffdbc04c7b
hostip.c: fix leak of addrinfo
When creating a dns entry, the addrinfo is passed into the entry on
success and needed deallocation by the caller on failure.

Change the signature to have Curl_dnscache_mk_entry() *always* take
ownership of the addrinfo, even on failure. Change parameter to address
of pointer so that call always clears it.

This makes the handling of failures to Curl_dnscache_mk_entry() simpler.

Fixes #20465
Closes #20468
2026-02-02 23:29:45 +01:00
Viktor Szakats
a84b041281
build: tidy up curl-specific fstat calls and stat struct type
To avoid redefining the `fstat` system symbol, and to clarify
`struct_stat` is a curl symbol.

- introduce `curlx_fstat()` macro and use it.
- rename `struct_stat` to `curl_struct_stat`.

Also:
- tests: replace direct `curlx_win32_stat()` call with `curlx_stat()`.
- checksrc: disallow direct `_fstati64` and `fstat()` calls, except in
  examples.

Closes #20496
2026-02-02 18:57:13 +01:00
Viktor Szakats
9630593650
build: use more const
Mostly with `char *` types.

Also:
- mime, x509asn1, tool_operate, lib3207: drop redundant casts.
- examples/smooth-gtk-thread: add missing variable declaration.
- reduce variable scopes.
- tests/server: move `data_to_hex()` to its only user: `sws`.

Closes #20489
2026-02-02 12:32:49 +01:00
Viktor Szakats
66bb641331
ftp: drop single-caller local verbose function
Closes #20495
2026-02-02 12:28:13 +01:00
Viktor Szakats
4728efe082
ftp: replace a curlx_free() with curlx_dyn_free()
On an error path.

Follow-up to f4beef524a #12638

Closes #20494
2026-02-02 12:28:13 +01:00
Viktor Szakats
96fa42c7c0
build: tidy up local lseek() mappings
- stop redefining system symbol `lseek`, by introducing `curl_lseek()`.
- handle AmigaOS quirk within the macro mapping.
- add missing parenthesis to `LSEEK_ERROR` values.
- tool_util: use curl `lseek` macros in `tool_ftruncate64()`.
- move `LSEEK_ERROR` to right-hand side of if expressions.
- checksrc: disallow direct uses of `_lseeki64`, `llseek`, `lseek`.

Closes #20488
2026-02-01 17:29:39 +01:00
Viktor Szakats
3003c32cb2
tidy-up: miscellaneous
- INSTALL-CMAKE.md: add missing periods, text fixes.
- md4, md5: sync variables names.
- curl_trc: sync an argument type.
- docs/examples: sync debug/trace function copies, constify, tidy-ups.
- replace commented code with `#if 0`.
- drop redundant parenthesis (macro values, `return`, around single
  variables, function calls).
- fix indentation, apply clang-format in places.

Closes #20481
2026-02-01 00:54:23 +01:00
Viktor Szakats
9c3fcb8a32
vtls: dedupe common on-session-reuse logic
Closes #20475
2026-01-30 13:27:03 +01:00
Viktor Szakats
97a294688f
ssh: dedupe state change function
Closes #20473
2026-01-30 13:27:03 +01:00
Viktor Szakats
c2d7bfa992
http2: dedupe nghttp2 verbose frame print function
Closes #20472
2026-01-29 19:22:00 +01:00
Viktor Szakats
0f5006f50d
md4, md5: replace custom types with uint32_t
Closes #20469
2026-01-29 15:01:16 +01:00
Viktor Szakats
ea044c5e65
setup-os400.h: drop no longer used custom type u_int32_t
Unused since bb55293313.

Closes #20470
2026-01-29 14:58:03 +01:00
Viktor Szakats
f95c79a988
send: drop CURL_UNCONST() from buffer argument on most platforms
Keep it on platforms requiring a non-const buffer. These are AmigaOS and
OS400.

Also:
- replace `SEND_QUAL_ARG2` with boolean macro `SEND_NONCONST_ARG2`.

Closes #20463
2026-01-29 03:42:09 +01:00
Viktor Szakats
483f4291fb
build: replace send/recv with swrite/sread where missing
Also:
- checksrc: ban `send` and `recv`, as documented in `CODE_STYLE.md`.

Follow-up to 9a2663322c #17572
Ref: a585cc35e5 #20097
Ref: #20441

Closes #20459
2026-01-28 14:39:22 +01:00
Viktor Szakats
feb52be197
build: assume stdint.h
curl requires `stdint.h` from C99, and no longer builds without it since
v8.18.0 (after dropping VS2008 support). Assume it's available, drop
feature checks.

Also:
- drop duplicate `stdint.h` includes.
- introduce internal `HAVE_UINTPTR_T`, enabled by default.
- OS400: disable `HAVE_UINTPTR_T`.
- build: keep cmake pre-fill and `cmp-config.pl` exception because cmake
  and autotools both detect `stdint.h` implicitly.

Co-authored-by: Dan Fandrich
Ref: #20405
Ref: #20384
Follow-up to 2e1a045d89 #17931

Closes #20406
2026-01-28 12:05:20 +01:00
Christian Schmitz
e788d9d2c7
imap: fix custom listing
Add test 1847 and 1848.

Fixes #20356
Closes #20360
2026-01-28 11:37:26 +01:00
Stefan Eissing
cf4164fa8d
vquic: handle SOCKEMSGSIZE correctly
Report UDP packets with SOCKEMSGSIZE as being "sent" to progress
the send buffer properly on PMTUD probes.

Reported-by: Daniil Gentili
Fixes #20440
Closes #20448
2026-01-28 11:23:10 +01:00
Itay Bookstein
05367694ec
cf-socket: use SOCK_CLOEXEC in socket_open when available
To close the possible race between socket() and fcntl(), we use
SOCK_CLOEXEC instead of fcntl() when it is available.

Closes #20442
2026-01-28 09:41:48 +01:00
Stefan Eissing
0f042efcb1
h2+h3: align stream close handling
For HTTP/2, add error code description to close failures.

For HTTP/3, add special handling like in HTTP/2 when streams
have been rejected or an error comes during the response body
and we are not interested in the body.

Closes #20207
2026-01-28 09:39:30 +01:00
Viktor Szakats
2f7d37f54a
windows: USE_WINSOCK to guard winsock2 code (where missing)
Replacing `_WIN32`.

Also:
- tool_doswin: guard possibly non-portable socket code with
  `USE_WINSOCK`. The socket is cast to `HANDLE` and passed to
  win32 API `SetStdHandle(STD_INPUT_HANDLE, ...)`.
- lib/setup-win32.h: move `#undef`s before their `#define` pair.

Closes #20455
2026-01-28 03:27:20 +01:00
Daniel Stenberg
1b50dcc2ab
tls: remove checks for DEFAULT
Since 9d8998c994, the setopt code changes input DEFAULT to an
actual more specific TLS version (1.2) for the backends to use and check
for.

This means that the default value (0L) cannot and should not actually be
used when the TLS backends run. This change adds asserts to verify that
and removes code that accepts the DEFAULT value as a valid version with
the TLS version functions' logic.

Applications can still set a specific lower version if they want (1, 1.0
or 1.1).

Closes #20453
2026-01-27 23:42:09 +01:00
Stefan Eissing
065b149df0
OpenSSL: check reuse of sessions for verify status
OpenSSL records its peer verification status inside its SSL_SESSION
objects. When a session is later reused, the SSL connection inherits
this verify status.

Session keys prevent reuse of sessions between connections that verify
the peer and those who do not. However, when Apple SecTrust is used
to verify a connection, this does not update the Sessions verify
status (and there is no setter). On session reuse, OpenSSL fails
the verification and Apple SecTrust cannot verify either since the
certificate peer chain is not available.

Fix this by checking the verification status on session reuse and
remove the session again if the peer needs to be verified, but the
session is not.

Reported-by: Christian Schmitza
Fixes #20435
Closes #20446
2026-01-27 14:03:47 +01:00
Arnav-Purushotam-CUBoulder
9b20a672b8
include: mask computed auth/proto bitmasks to 32 bits
GCC 15.2 warns when assigning computed "all" bitmask macros to 32-bit
flag types because negated masks expand to the full width of unsigned
long/long on 64-bit platforms.

Mask these macros to a 32-bit domain so they do not set high bits and
avoid -Woverflow/-Wconversion warnings in callers.

Reported-by: Patrick Monnerat
Fixes #20242
Closes #20416
2026-01-26 13:48:05 +01:00
Viktor Szakats
4e5908306a
build: constify memchr()/strchr()/etc result variables (cont.)
Assisted-by: Rudi Heitbaum
Fixes #20420
Follow-up to 7dc60bdb90 #20425
Follow-up to 0e2507a3c6 #20421

Closes #20428
2026-01-25 14:20:37 +01:00
Viktor Szakats
6974bd7cc8
curlx: dedupe basename copies into curlx_basename()
Also stop redefining system `basename()` symbol. Call `curlx_basename()`
instead, and map that to `basename()` if available.

Closes #20424
2026-01-25 12:21:54 +01:00
Viktor Szakats
0e2507a3c6
build: constify memchr()/strchr()/etc result variables
And a few variables around.

There remain cases where the accepted pointer is const, yet the returned
pointer is written to.

Partly addressing (glibc 2.43):
```
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
  strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
  pointers into their input arrays now have definitions as macros that
  return a pointer to a const-qualified type when the input argument is
  a pointer to a const-qualified type.
```
Ref: https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html

Reported-by: Rudi Heitbaum
Ref: #20420

Closes #20421
2026-01-25 12:21:54 +01:00
Daniel Stenberg
7dc60bdb90
noproxy: simplify, don't mix const non-const in strchr()
Ref: #20420
Closes #20425
2026-01-25 11:02:24 +01:00
Viktor Szakats
3150ac7000
build: fix unused variables/values/code in non-verbose builds
Seen in GHA/codeql builds.

One of them also affected wolfSSL < 3.9.10 builds.

61093e2a81 #20353
Cherry-picked from #20404
Closes #20417
2026-01-24 02:12:54 +01:00
Michał Antoniak
55ea2b424d setopt: fix checking range for CURLOPT_MAXCONNECTS
- Use upper limit INT_MAX instead of UINT_MAX.

UINT_MAX doesn't work as the max value for the variable since it is
passed as a long and becomes -1 on platforms that have same sized
int and long, like Windows.

Closes https://github.com/curl/curl/pull/20414
2026-01-23 16:30:09 -05:00
Viktor Szakats
b81341e8f5
tidy-up: Markdown, clang-format nits
- drop leading indent from Markdown.
- switch to Markdown section markers where missing.
- move `&&` and `||` to the end of the line (C, Perl).
- openssl: add parenthesis to an if sub-expression.
- misc clang-format nits.
- unfold Markdown links.
- SSL-PROBLEMS.md: drop stray half code-fence.

Closes #20402
2026-01-22 23:44:47 +01:00
Stefan Eissing
2a6ae3684e
socketpair: set SO_NOSIGPIPE where possible
Set SO_NOSIGPIPE on socketpair/inet-simulated socketpair
implementations. eventfd and pipe() do not need/want it.

Closes #20397
2026-01-22 17:18:16 +01:00
Viktor Szakats
66ad54e46b
cmake: add CURL_DROP_UNUSED option to reduce binary sizes
To enable known linker options dropping unused, dead, code and data from
the executables built.

Useful to reduce binary sizes for curl, libcurl shared lib and apps
linking static libcurl. It's effective on both "unity" and non-unity
builds. Aligning "unity" build sizes with default, non-unity ones.

Supported platforms: Apple, MSVC, llvm/clang and GCC on all tested
platforms: Linux, BSDs, Windows, MSYS2/Cygwin, Android, MS-DOS.

Notes:
- Static libraries grow 20-30% with non-Apple toolchains.
  This effect is controlled by separate, optional compiler flags on
  non-Apple. This patch enables them automatically for public binaries
  (libcurl and curl tool), and leaves them off for internal/test ones.
- MSVC enables this option by default for 'Release' configurations.
  The curl build option has no effect on it.
- Observed effect on VS2010 is negligible. VS2012+ is recommended.
- Works with LTO, Fil-C.
- No observed/conclusive effect on build speed.
- On Windows with clang/gcc (mingw-w64/MSYS2/Cygwin) it also enables
  `-fno-asynchronous-unwind-tables` as a workaround to make
  the toolchain options actually work.
  Ref: https://sourceware.org/bugzilla/show_bug.cgi?id=11539
  Thanks-to: Andarwinux

Also:
- GHA: enable in Linux and MinGW jobs to test it. Size changes:

  - linux aws-lc H3:
    curl: 2000000 -> 1937152, libcurl.a: 2065724 -> 2716532 bytes
  - macos clang HTTP-only:
    curl: 1364376 -> 128799 bytes, libcurl.a: unchanged
  - macos llvm MultiSSL:
    curl: 410056 -> 405720, libcurl.dylib: 1350336 -> 1348480 bytes
  - mingw schannel c-ares U:
    curl: 1588736 -> 1507328, libcurl-d.a: 3322040 -> 3884746 bytes
    bld: 34 -> 35MB

- GHA: enable in MSVC and Apple jobs to reduce disk footprint, with no
  obvious downside. Size changes:

  - AppVeyor CI VS2019:
    curl: 2339840 -> 1295872, libcurl-d.dll: 3155968 -> 1900544 bytes
    bld: 161 -> 97MB
  - AppVeyor CI VS2022 clang-cl:
    curl: 2933248 -> 2332160, libcurl-d.lib: 4762688 -> 5511330 bytes
    bld: 133 -> 121MB
  - AppVeyor CI VS2022 HTTP-only:
    curl: 3514368 -> 2177024, libcurl-d.lib: 2538420 -> 3151740 bytes
    bld: 137 -> 83MB
  - GHA intel:
    curl: 2629120 -> 2023424, libcurl-d.lib: 4366652 -> 5350670 bytes
    bld: 86 -> 69MB
  - GHA arm64:
    curl: 2832896 -> 2063872, libcurl-d.lib: 4690616 -> 5597250 bytes
    bld: 82 -> 66MB

Refs:
https://maskray.me/blog/2021-02-28-linker-garbage-collection
https://web.archive.org/web/20110811230637/msdn.microsoft.com/en-us/library/bxwfs976.aspx (VS2010)
https://learn.microsoft.com/cpp/build/reference/opt-optimizations
https://learn.microsoft.com/cpp/build/reference/gy-enable-function-level-linking

Closes #20357
2026-01-22 17:08:20 +01:00
Daniel Stenberg
d89bc6b219
asyn-ares: abort with OOM error when Curl_dnscache_mk_entry fails
Closes #20385
2026-01-21 23:32:18 +01:00
Viktor Szakats
dfef594213
build: opt-in MSVC to C99-style verbose logging logic
MSVC does not advertise itself as C99 via `__STDC_VERSION__`, but
supports variadic macros in all curl-supported versions. Fix by
explicitly enabling C99 verbose string logic for MSVC.

With verbose logging enabled (default), this makes logging perform
better, on par with clang/gcc (and other C99) builds. (With the cost
of extra binary size.) With verbose logging disabled, it excludes all
verbose logging related strings and code from the binary. Before this
patch, MSVC used the C89 fallback code in both configs, which used
a fixed function call, with the called function deciding to actually
log or not, while also retaining the verbose log string in both configs.

Size comparison (bytes), schannel, static, debug, VS2022, local build:
curl-before-verbose.exe    4,024,832
curl-before-noverbose.exe  4,013,056
curl-after-verbose.exe     4,117,504
curl-after-noverbose.exe   3,928,064

In CI with non-verbose:
Before:
```
3274240 bytes: ./_bld/lib/Debug/libcurl-d.dll
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/53408629/job/htj7ps88q83ew9ww#L224

After:
```
3155968 bytes: ./_bld/lib/Debug/libcurl-d.dll
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/53408771/job/tp9epgjpef098vsr#L224

Idea-by: Arnav Purushotam
Ref: #20367
Ref: #20341
Follow-up to 61093e2a81 #20353

Closes #20387
2026-01-21 21:01:46 +01:00
Viktor Szakats
f24be5b36e
dynhds: drop duplicate includes
Already included via `dynhds.h`.

Closes #20389
2026-01-21 18:10:08 +01:00
Viktor Szakats
59e3b693f7
windows: test non-verbose builds, fix fallouts
- schannel: fix mixed-up declaration. (originally fenced infof for
  verbose, then changed to failf with the fence kept, then fence
  removed and variable marked as verbose, when in fact it's not, but
  not tested and caught in CI.
- fix two other fallouts.
- GHA/windows: disable verbose strings in a mingw job.
- appveyor: disable verbose strings in an MSVC job.
- appveyor: add way to pass any CMake option per-job.

Cherry-picked from #20387
Follow-up to 61093e2a81 #20353

Closes #20388
2026-01-21 15:25:40 +01:00
Viktor Szakats
61093e2a81
build: fully omit verbose strings and code when disabled
When the compiler supports C99.

- map logging functions to macro stubs when verbose logging is disabled
  and the compiler is C99. Make sure these stubs silence unused variable
  warnings for non-variadic arguments.
  Before this patch they mapped to function stubs, the same codepath
  used for C89 compiler in this configuration.

- introduce new macros to tell the compiler which code to include
  when verbose code is active, or inactive:

  - `CURLVERBOSE`: defined when verbose code is active.
    To enclose blocks of code only used for verbose logging.

  - `VERBOSE(statement);`:
    compile statement when verbose code is active.
    To mark code lines only used for verbose logging.

  - `NOVERBOSE(statement);`:
    compile statement when verbose code is inactive.
    To suppress warnings for arguments passed to logging functions via
    printf masks, e.g. `NOVERBOSE((void)ipaddress);`, yet keeping
    the warning in verbose builds.

  Note these macros are not the same as `CURL_DISABLE_VERBOSE_STRINGS`.
  Verbose code is always active in C89 mode (without variadic macro
  support).

- drop existing uses of `CURL_DISABLE_VERBOSE_STRINGS` where redundant,
  or replace with the above macros. Ending up reducing the number of
  `#ifdef`s, and also the number of lines.

Assisted-by: Daniel Stenberg
Assisted-by: Jay Satiro
Reported-by: Dan Fandrich
Fixes #20341
Refs: #12105 #12167

Closes #20353
2026-01-21 13:18:35 +01:00
Daniel Stenberg
e286589c71
multi: probe for IPv6 functionality in multi_init()
In some legacy systems IPv6 might dynamically work/not work and thus
curl needs to check/probe to see if it should indeed be used.

This change moves the probe that checks for working IPv6 to the multi
handle setup function instead of delaying it to when the first name
resolve is performed. This avoids a later tricky error path if the
socket cannot be created due to OOM.

Closes #20383
2026-01-21 09:38:31 +01:00