Commit Graph

16434 Commits

Author SHA1 Message Date
Viktor Szakats
e09a7b83d6
cf-https-connect: silence -Wimplicit-int-enum-cast with HTTPS-RR + clang 21
Fixing (seen in curl-for-win dev branch):
```
In file included from _a64-linux-gnu-bld/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c:34:
lib/cf-https-connect.c:681:28: error: implicit conversion from 'unsigned char' to enumeration type 'enum alpnid' is invalid in C++ [-Werror,-Wimplicit-int-enum-cast]
  681 |         enum alpnid alpn = rr->alpns[i];
      |                     ~~~~   ^~~~~~~~~~~~e
```

Ref: #21032

Closes #21057
2026-03-21 23:45:55 +01:00
Daniel Stenberg
789282cb8d
lib: drop support for < c-ares 1.16.0
Closes #20911
2026-03-21 23:37:59 +01:00
Scott Boudreaux
21fc17b265
md5/md4: enable unaligned access fast path on powerpc64
PowerPC64 (both big-endian and little-endian) supports efficient
unaligned memory access, similar to x86. This extends the existing
fast path that avoids byte-by-byte loads in the MD5 and MD4 SET/GET
macros.

On POWER8 ppc64le, this eliminates 3 shifts + 3 ORs per 32-bit word
load, replacing them with a single lwz (or lwbrx on big-endian).

Co Authored By Claude Opus 4.6 (1M context)

Closes #20985
2026-03-21 23:35:58 +01:00
Daniel Stenberg
77ed315096
progress: count amount of data "delivered" to application
... and apply the CURLOPT_MAXFILESIZE limit (if set) on that as well.
This effectively protects the user against "zip bombs".

Test case 1618 verifies using a 14 byte brotli payload that otherwise
explodes to 102400 zero bytes.

Closes #20787
2026-03-21 23:21:55 +01:00
Daniel Stenberg
fa13f373b2
netrc: skip malformed macdef lines
When skipping macdef lines inside netrc files, ignore it completely and
do not tokenize or bail out on bad quotes.

Verify in test 1672

Follow-up to 3b43a05e00

Spotted by Codex Security
Closes #21049
2026-03-21 23:20:49 +01:00
Daniel Stenberg
6026d76fdf
test1668: unit test the FTP 213 time response parser
Should make it harder to introduce regressions.

Closes #21051
2026-03-21 23:10:32 +01:00
Viktor Szakats
6c64d39dce
hostip: drop guard from Curl_resolver_error() definition
To sync with its declaration.

Fixing (seen when building trurl in curl-for-win):
```
ld.lld: error: undefined symbol: Curl_resolver_error
```
Ref: https://github.com/curl/curl-for-win/actions/runs/23388349475/job/68038915761#step:3:7469

Closes #21054
2026-03-21 22:42:38 +01:00
Daniel Stenberg
cc0c83c5f8
build: make NTLM disabled by default
NTLM has weak security and does not work over HTTP/2 or HTTP/3.

Enable in cmake or configure to get support for it.

Closes #20698
2026-03-21 15:30:03 +01:00
Daniel Stenberg
ceae02db04
rtmp: drop support
- librtmp has no test cases, makes no proper releases and has not had a
  single commit within the last year

- librtmp parses the URL itself and requires non-compliant URLs for this

- we have no RTMP tests

- RTMP was used by 2.2% of curl users (self-identified in the 2025
  survey)

Closes #20673
2026-03-21 14:56:06 +01:00
Stefan Eissing
5649b21297
curlx_now(), prevent zero timestamp
As code checks `curltime` values for zero and interprets this
as not-initialized or "forever" in several places, make sure
`curlx_now()` never returns a zero timestamp.

Closes #21034
2026-03-21 14:47:36 +01:00
Stefan Eissing
82009c4220
share: concurrency handling, easy updates
Replace the `volatile int dirty` with a reference counter
protected by a mutex when available.

Solve the problem of when to call application's lock function
by adding a volatile flag that indicates a share has been added
to easy handles in its lifetime. That flag ever goes from
FALSE to TRUE, so volatile might work (in the absence of a mutex).

(The problem is that the lock/unlock functions need 2-3
`curl_share_setopt()` invocations to become usable and there
is no way of telling if the third will ever happen. Calling
the lock function before the 3rd setopt may crash the
application.)

When removing a share from an easy handle (or replacing it with
another share), detach the easy connection on a share with a
connection pool.

When cleaning up a share, allow this even if it is still used in
easy handles. It will be destroyed when the reference count
drops to 0.

Closes #20870
2026-03-21 14:42:49 +01:00
Stefan Eissing
745344ea4e
hostip: fix !no_signal mixup in resolve refaactor
When extracting the resolve case using alarm timers, the check for "we
are not allowed to use signals" was refactored wrong.

Follow-up to 96d5b5c688

Closes #21047
2026-03-21 14:28:54 +01:00
Viktor Szakats
a8bc4cbcfe
build: assume snprintf() in mprintf, drop feature check
- it was already required for `curl_*printf()` float/double support.
- some curl tests always fail without it.
- it was already assumed to be present to build test servers.
  Source code did not check for `HAVE_SNPRINTF` detection variable.
- it was already required to build examples.

Windows builds stopped using this detection and the function via earlier
commits.

Follow-up to 64f28b8f88 #20765
Follow-up to 935b1bd454 #9570 #9569

Closes #20763
2026-03-21 13:30:37 +01:00
Viktor Szakats
89043ba906
cmake: drop support for CMake 3.17 and older
Require CMake 3.18 (2020-07-15) or newer, up from 3.7 (2016-11-11)
prior to this patch.

This requirement also applies to the distributed `curl-config.cmake`.

To allow dropping compatibility code maintained for old versions, and to
use features which were unpractical in separate code paths. Also to make
testing, documentation and development easier, CI builds faster due to
CMake performance improvements over time. (e.g. integration tests on
macOS run 8x faster (10 minutes is now under 1.5m) in CI, 2.5x faster on
Windows.)

CMake offers pre-built binaries for major platforms. They work without
an install step, just by unpacking and pointing the cmake command to
them. Making upgrades easy in many cases:
https://cmake.org/download/
https://cmake.org/files/
https://github.com/Kitware/CMake/releases

CMake 3.18 brings these feature as generally available when building or
consuming curl/libcurl:

LTO support, improved performance, `pkg-config` and interface target
support, `OBJECT` target (for faster libcurl builds), modern invocation
with `-S`/`-B` options, better support for custom linker options,
FetchContent, `GnuTLS::GnuTLS` target, `--verbose` and `--install`
options, `CMAKE_GENERATOR` env, last but not least unity mode and Ninja
generator.

For maximum build speed, use:
`-DCMAKE_UNITY_BUILD=ON -DCURL_DROP_UNUSED=ON`

As for deprecations, C++11 is required to build CMake itself, which may
be a limit on some platforms. autotools continues to cover them.

Follow-up to 9bcdfb3809 #20408
Follow-up to a7c974e038 #19902
Follow-up to dfbe035c8b #10161
Discussion: https://github.com/curl/curl/discussions/18704

Closes #20407
2026-03-21 13:24:47 +01:00
Viktor Szakats
8ffe0db8f8
lib: move all UNITTEST prototypes to C files (cont.)
Follow-up to 98d8e82c74 #21014

Closes #21040
2026-03-21 13:14:46 +01:00
Daniel Stenberg
f36a8ac5a2
dnscache.h: include curlx/timeval.h for struct curltime
Follow-up to 96d5b5c688

Closes #21045
2026-03-21 12:27:34 +01:00
Daniel Stenberg
322db3efc0
ftp: make the MDTM date parser stricter (again)
A previous refactor made the parser more lenient and this takes it back
to making sure only ascii digits are accepted.

Added test 1684 to verify

Follow-up to 304b5183fd

Pointed out by Codex Security

Closes #21041
2026-03-21 12:25:14 +01:00
Stefan Eissing
96d5b5c688
dnscache: own source file, improvements
- Rename `Curl_resolv_unlink()` to `Curl_dns_entry_unlink()`.
- Change `Curl_dnscache_get()` to return CURLcode result. Returns
  now `CURLE_COULDNT_RESOLVE_HOST` for "negative" cache entries.
- Add `Curl_dnscache_add_negative()` to put a "negative" entry
  into the cache.

Closes #20864
2026-03-21 12:04:36 +01:00
Stefan Eissing
b0f6e9a3d7
openssl channel_binding: lookup digest algorithm without NID
Use an alternate OpenSSL API to get the digest algorithm tied
to a certificate signature to compute the channel binding.

Fixes #20590
Reported-by: Rob Crittenden
Closes #20734
2026-03-21 12:00:17 +01:00
Stefan Eissing
9bc8b078eb
multi: improve wakeup and wait code
- Split WINSOCK and POSIX code in `multi_wait()` as the ifdef'ery
  was becoming unreadable
- define `ENABLE_WAKEUP` to mean the wakeup socketpair is enabled,
  no additional USE_WINSOCK check needed. Under WINSOCK
  `ENABLE_WAKEUP` is not defined, so it's availability is as before
  under the double defined() checks
- When the multi handle has "alive" transfers, the admin handle's
  pollset include the wakeup receive socket. This results in the
  admin handle running when someone uses `curl_multi_wakeup()`.
- Without any "alive" transfers, the wakeup socket is removed from
  the pollset. Otherwise, event based processing would never finish,
  eg. leave the event loop.
- The wakeup socket was never registered for event processing before,
  e.g. `curl_multi_wakeup()` never worked in that mode.
- Adjust test exepectations on socket callback invocations and
  number of sockets appearing in waitfds sets.

Closes #20832
2026-03-21 11:58:24 +01:00
Stefan Eissing
708b3f8b4e
wolfssl: fix handling of abrupt connection close
A closed connection without TLS notify shutdowns, has been reported as a
correct EOF instead of an error. Fix the error handling in wolfSSL
backend receive handling.

Spotted by Codex Security

Closes #21002
2026-03-20 17:48:56 +01:00
Daniel Stenberg
1eb9096897
transfer: enable custom methods again on next transfer
`http_ignorecustom` is set on redirect handling but was not reset
between transfers, so once a redirect occurs in the new follow modes,
custom request methods were ignored for later transfers on the same
handle.

Follow-up to fb13923dd6

Detected by Codex Security

Closes #21037
2026-03-20 17:46:50 +01:00
Daniel Stenberg
f2ba8f0613
protcol.h: fix the CURLPROTO_MASK
It had an 'f' too few. Also provide CURLPROTO_WS* unconditionally
internally, so that code can depend on them in all builds.

Follow-up to cd5ca80f00

Spotted by Codex Security

Test case 3219 added to catch this next time.

Closes #21031
2026-03-20 17:24:01 +01:00
Daniel Stenberg
b9e179e4e5
urldata: make speeder_c uint32
This counter is meant to virtually never wrap.

Follow-up to e3691612ea

Spotted by Codex Security

Closes #21036
2026-03-20 16:56:48 +01:00
Daniel Stenberg
6d1d50d65d
protocol: use scheme names lowercase
When composing the <scheme>_proxy environment variable, we assume the
handler->scheme name is already lowercase.

This makes unit test 1627 verify that is the case.

Follow-up to c294f9cb56

Spotted by Codex Security

Closes #21033
2026-03-20 16:00:30 +01:00
Daniel Stenberg
0b182ae529
file: init fd to -1 to prevent close fd 0 on early failure
Spotted by Codex Security

Closes #21029
2026-03-20 15:00:21 +01:00
Viktor Szakats
2cdb2209da
getinfo: initialize PureInfo field used_proxy
Found by Codex Security

Follow-up to cc04c73677 #12719

Closes #21020
2026-03-20 13:47:32 +01:00
Daniel Stenberg
e3ed70ce72
url: use the socks type for socks proxy
Reported by Codex Security

Closes #21025
2026-03-20 13:17:22 +01:00
Daniel Stenberg
14782b36fe
x509asn1: fixed and adapted for ASN1tostr unit testing
- move defines to header file
- make bit2str require < 8 unused bits
- make bool strings stricter
- make UTime2str show + or - for custom time zones
- removed unused 'type' argument to ASN1tostr() function
- fix int2str for negative values. All values below 10000 are now shown
  in decimal properly, also possibly negative values.

Add unit test 1667 to verify ASN1tostr

Closes #21013
2026-03-20 13:03:40 +01:00
Daniel Stenberg
98d8e82c74
lib: move all UNITTEST prototypes to C files
- make extract-unit-protos handle multi-line prototypes - but they need
  to be above the implementation

- Prototypes for static functions we use in unit tests should not be in
  header files. We generate lib/unitprotos.h for this purpose

- Removed some function wrappers written for unit tests and make them
  use UNITTEST function directly.

- Renamed time2str() in the tool to timebuf() since we have the same
  name in lib/ and in unit tests they can both be used non-static in a
  build.

This reverts commit f95fadd116.

Follow-up to #21010

Closes #21014
2026-03-20 07:47:57 +01:00
Viktor Szakats
a9e341a469
optiontable: replace stdin with filename arg, harden open() call
Closes #21008
2026-03-19 15:06:43 +01:00
Viktor Szakats
f95fadd116
x509asn1: move declaration to header
Fixing clang-tidy warning:
```
tests/unit/unit1666.c:50:12: error: call to undeclared function 'encodeOID'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]
   50 |   result = encodeOID(dbuf, oid, oid + spec->size);
      |            ^
```
Ref: https://github.com/curl/curl/actions/runs/23297585235/job/67749144361?pr=21008#step:46:736

Follow-up to 673e14cd33 #21003

Closes #21010
2026-03-19 15:04:12 +01:00
Daniel Stenberg
673e14cd33
x509asn1: improve encodeOID
- return error on zero length input
- return error on OOM or doing too large output
- fix full 32-bit number support
- fix the broken handling of the first and second numbers
- support up to 32-bit minus 80 for the second number
- a field with a leading 0x80 is now considered an error, since it only
  works as padding and is then no longer the shortest possible version

Add unit tests in 1666

Bonus: removed the last argument to OID2str() as it was always set TRUE.

Closes #21003
2026-03-19 13:55:34 +01:00
Viktor Szakats
6c0772fd7f
openssl: fix memory leaks in ECH code (OpenSSL 3)
Also drop an unnecessary cast.

Found by Codex Security

Follow-up to a362962b72 #11922

Closes #20993
2026-03-19 12:02:10 +01:00
Viktor Szakats
86c25c06c9
x509asn1: fix to return error in an error case from encodeOID()
Found by Codex Security

Follow-up to d8b0318ad6 #3582

Closes #20991
2026-03-19 11:17:17 +01:00
Viktor Szakats
59405ffb7d
build: enable -Wimplicit-int-enum-cast compiler warning, fix issues
Offered by clang 21+.

Closes #20990
2026-03-19 11:17:17 +01:00
Viktor Szakats
e345dfb958
asyn-ares: drop orphaned variable references
In rare, conditional `#if` branches.

Found by Codex Security

Follow-up to ac7e2c3dc6 #17450
Follow-up to 7bf576064c #17167

Closes #20999
2026-03-19 02:24:06 +01:00
Viktor Szakats
d986b89c88
rand: use BCryptGenRandom() in UWP builds
Also:
- fix build configuration to correctly set Win10 target in the mingw-w64
  CI build, to enable the `BCryptGenRandom()` prototype in v6+ SDK
  headers.

Ref: https://learn.microsoft.com/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom

Issue raised by Codex Security

Closes #20983
2026-03-18 14:47:39 +01:00
Stefan Eissing
41aaac61e2
lib: always use Curl_1st_fatal instead of Curl_1st_err
Curl_1st_err() does not return the second error if the first result is
CURLE_AGAIN. This may cause errors to not become noticeable when they
should be.

Replace all use of Curl_1st_err() with Curl_1st_fatal(), which handles
CURLE_AGAIN as a not-a-real-error case.

Closes #20980
2026-03-18 13:38:51 +01:00
Viktor Szakats
454db7aeee
badwords: prefer 'null-terminated'
Aligning with existing text.

Closes #20979
2026-03-18 11:40:13 +01:00
Viktor Szakats
578ee6b79b
gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings
Extend `#pragma diagnostic push`/`pop` guards to the whole codebase
(from tests and examples only) to disable it for GCC <4.6. Rename guard
to `CURL_HAVE_DIAG` and make it include llvm/clang to be interchangeable
with `__GNUC__ || __clang__` in this context.

The above means no longer disabling certain warnings locally, so pair
this with disabling all picky warnings for GCC <4.6.

Also:
- drop global workarounds for misbehaving GCC <4.6 compiler warnings.
  Not needed with picky warnings disabled.

Reported-by: fds242 on github
Reported-by: Sergey Fedorov
Thanks-to: Orgad Shaneh
Follow-up to f07a98ae11 #20366
Fixes #20892
Fixes #20924
Closes #20902
Closes #20907
2026-03-18 11:33:37 +01:00
Ercan Ermis
c3f04e76ae
ftp: reject PWD responses containing control characters
A malicious or compromised FTP server could include control characters
(e.g. bare \r, or bytes 0x01-0x1f/0x7f) inside the quoted directory path
of its 257 PWD response. That string is stored verbatim as
ftpc->entrypath and later sent unescaped in a CWD command on connection
reuse via Curl_pp_sendf(), which performs no sanitization before
appending \r\n.

Reject the entire path if any control character is encountered during
extraction so that tainted data never reaches a subsequent FTP command.

Add test case 3217 and 3218 to verify. Adjusted test 1152 accordingly.

Closes #20949
2026-03-18 11:24:41 +01:00
Daniel Stenberg
3f06e27502
urlapi: make dedotdotify handle leading dots correctly
Paths starting with one or two leading dots but without a following
slash were not handled correctly.

Follow-up to c31dd6631f

Extended test 1395 accordingly with a set of new test string.

Reported by Codex Security

Closes #20974
2026-03-18 11:14:20 +01:00
Daniel Stenberg
a43ea5943b
http2: clear the h2 session at delete
When calling nghttp2 to delete session, clear the pointer to avoid risk
of UAF.

Pointed out by Codex Security

Closes #20975
2026-03-18 10:34:48 +01:00
Daniel Stenberg
02e04eaee7
asyn-ares: fix HTTPS-lookup when not on port 443
Follow-up to 8d0bfe74fb

Spotted by Codex Security

Closes #20966
2026-03-18 10:25:52 +01:00
Daniel Stenberg
a327a5bded
netrc: refactor into smaller sub functions
Fixes #20950 - test 685 is extended for this
Closes #20932
2026-03-17 16:51:38 +01:00
Daniel Stenberg
a46816b4cb
imap: reset the UIDVALIDITY state between transfers
uidvalidity_set and mb_uidvalidity_set flags were never reset, leaving a
risk for stale UIDVALIDITY state across transfers and mailbox switches.

Follow-up to fb6a4802d7

Spotted by Codex Security

Closes #20962
2026-03-17 16:31:53 +01:00
Daniel Stenberg
ae09e5bf0d
curl_get_line: error out on read errors
Missing ferror handling in Curl_get_line causes infinite loops on I/O
errors, leading to denial-of-service hangs for config/cache file loads.

Follow-up to 769ccb4d42

Pointed out by Codex Security

Closes #20958
2026-03-17 16:14:08 +01:00
Stefan Eissing
adda11330b
transfer: enhance secure check
Introduce `Curl_xfer_is_secure(data)` that returns TRUE for transfers
that happen(ed) over a end-to-end secured connection, e.g. SSL.

Add test1586 to verify behaviour for http: transfers via a https: proxy.

Reported-by: lg_oled77c5pua on hackerone

Closes #20951
2026-03-17 15:56:02 +01:00
Stefan Eissing
f1a5343f5e
urldata: remove trailers_state
It's not used anywhere. Remove `data->state.trailers_state` completely.

Closes #20960
2026-03-17 15:32:04 +01:00
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