Commit graph

16955 commits

Author SHA1 Message Date
Daniel Stenberg
2687751471
protocol: simpler Curl_getn_scheme runs faster
Iterating unit test 1627 50,000 times show the new version to be 31%
faster on my machine.

- unit1627: add more test strings, In particular three, five and six letter
  non-existing schemes.

- remove scripts/schemetable.c, not used anymore

Closes #22658
2026-08-24 22:57:40 +02:00
Viktor Szakats
c2676bf9e6
vssh: silence gcc-11 -Wnull-dereference, dedupe CURL_EASY_STR() calls
Silencing:
```
In file included from libcurl_unity.c:179:
vssh/vssh.c: In function ‘Curl_ssh_setup_pkey.part.0’:
vssh/vssh.c:423:50: error: potential null pointer dereference [-Werror=null-dereference]
  423 |        CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY)[0]) {
libtool: compile:  gcc -DHAVE_CONFIG_H -I../include -I../lib -I../lib -I. -DBUILDING_LIBCURL -DCURL_STATICLIB -DUNITTESTS -D_GNU_SOURCE -Werror-implicit-functi
```
Ref: https://app.circleci.com/pipelines/gh/curl/curl/20825/workflows/c3eb591b-5a7d-40da-baa8-d2d9980b0cb2/jobs/181277

Follow-up to c8df3defd9 #22628

Closes #22656
2026-08-24 12:28:57 +02:00
Viktor Szakats
a1bca29bdd
lib: silence gcc-16 compiler warnings -Wmaybe-uninitialized
Seen in the 'curl-for-win / Windows gcc zlib-classic (x64)' CI job,
after it got an upstream upgrade from gcc-15 to gcc-16:
```
lib/http.c:206:6: error: 'out.str' may be used uninitialized [-Werror=maybe-uninitialized]
  206 |   if(header_has_value(&header, &out)) {
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/api.h:188:3: error: 'guard.data' may be used uninitialized [-Werror=maybe-uninitialized]
  188 |   Curl_mapi_enter((g), (m), CURL_MAPI_FN_##fn, (r)) && (m)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/multi.c:1695:6: note: in expansion of macro 'CURL_MAPI_ENTER'
 1695 |   if(CURL_MAPI_ENTER(&guard, m, multi_poll, &mresult)) {
      |      ^~~~~~~~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/32626356576/job/97162205296#step:3:4906

Closes #22651
2026-08-24 09:38:10 +02:00
Kieran Gannon
a334227e8a
tidy-up: fix typos in docs and comments
Correct grammar and spelling in documentation and source comments. Also
fix the Aspell configuration key and one user-facing OpenSSL error
message.

Closes #22647
2026-08-23 22:27:41 +02:00
Daniel Stenberg
85c8f6f3a5
cookie: allow loading cookies for localhost
The added code to avoid loading PSL cookies from files from PR #22500
(c041895, not shipped in a release), calls psl_is_public_suffix(),
returns TRUE also for "localhost" (!).

We now allow cookies again for localhost. Added test 320 to verify.

Reported-by: Athos Ribeiro
Fixes #22645
Closes #22646
2026-08-23 22:16:47 +02:00
Stefan Eissing
7e7ee16dd3
ws: fix write callback error handling
When websocket writes out data thought the registered write callback and
that returns an error, clear the write buffers, so a sub-sequent flush
will not attempt another write. The transfer is failed at that point and
should no longer invoke the callback.

Fixes #22627
Reported-by: Scott Talbert
Closes #22634
2026-08-21 23:01:23 +02:00
Stefan Eissing
2f1dda9691
u8_strset: start with 8 default entries
The previous 4 entries were exhausted on simple command lines, depending
on environment/build. Grow the initial size to 8 to avoid early allocs.

Closes #22633
2026-08-21 11:25:04 +02:00
Stefan Eissing
c8df3defd9
lib: new easy option string storage
Change the storage of easy handle option strings from an array sized for
all possible options to a hash set to reduce memory footprint.

Give the hash set initially room for 4 strings, with first allocation
happening when it goes beyond that. Measurements without test suite
and a forced fail on growing the set gives:

Size Result
2    1261 tests out of 1951 reported OK: 64%
4    1792 tests out of 1951 reported OK: 91%
8    1944 tests out of 1951 reported OK: 99%
16   1949 tests out of 1951 reported OK: 99%
32   single fail of 3211, unit test for u8_strset

Add u8_strset that keeps the tuples (uint8_t id, char *str)
and allows set/unset by `id`. Add that as data->set.strings.

Define MACROS
* CURL_EASY_STR(data, id) for access
* CURL_EASY_STR_SET(data, id, s) for setting, making a copy
* CURL_EASY_STR_SETN(data, id, s) for setting, no copy
* CURL_EASY_STR_CLEAR(data, id) for unsetting
* CURL_EASY_STR_CLEAR0(data, id) for unsetting and zero-ing value

Add `data->set.str_copypostfields` to handle former `STRING_COPYPOSTFIELDS`
string that was not always a string and could carry NUL bytes.

Add unit tests to test3211.

Closes #22628
2026-08-21 09:36:07 +02:00
Fred Klassen
961c95fea6
openssl: fix DER buffer leak in Apple SecTrust verification
`ossl_chain_get_der()` allocates a DER encoding of each peer certificate
via `i2d_X509()`, but `Curl_vtls_apple_verify()` only copies it into a
CFData and never frees the original. This leaks per certificate, per
handshake, whenever USE_APPLE_SECTRUST is used with the
OpenSSL/LibreSSL/BoringSSL backend.

Fix frees the buffer inside openssl.c itself, so the GnuTLS backend
(which borrows rather than allocates) is unaffected.

Closes #22631
2026-08-21 09:30:36 +02:00
Alhuda Khan
2ba2fe3540
ldap: base64-encode LDIF values beginning with colon or less-than
A value whose first byte is ':' or '<' is not a SAFE-INIT-CHAR per RFC
2849 and must be base64-encoded, but ldap_value_needs_base64() and the
inline check in oldap_recv() only encoded on a control byte or
leading/trailing blank. Such a value was emitted verbatim, producing
LDIF that strict parsers reject.

Closes #22339
2026-08-21 00:16:12 +02:00
Stefan Eissing
aab0518d04 url: fix handling of empty user in ntml matching
Line should already have been removed in 7103a93, but neither
humans nor clankers caught it. tststs...

Prior to this change it appears all reuse of empty cred connection was
blocked for ntlm instead of the intended behavior of allowing
reuse in the limited circumstance when it is the same connection used by
the transfer before.

Closes https://github.com/curl/curl/pull/22629
2026-08-20 11:35:43 -04:00
Daniel Stenberg
9b29495863
http: custom Authorization: header overrides Negotiate
As documented and as it does for other methods.

Difficult to test since it needs a successful kerberos ticket.

Reported-by: sdgh179 on github
Fixes #22610
Closes #22622
2026-08-19 23:39:09 +02:00
Daniel Stenberg
695aa15743
urldata: remove the aptr struct
Move the two remaining fields into the state struct instead, within the
HTTP ifdef.

Also: make the AWS sigv4 code always rely on the http_host value. It
was previously conditionally trying to also work if it was not set, but
that logic was not creating an identical copy so it would fail.

Closes #22620
2026-08-19 07:49:55 +02:00
Viktor Szakats
b8b1dc0a0d
config-win32.h: drop UWP, c-ares, simplify more
UWP requires VS2015+. Project files have no support for c-ares.
Drop redundant guard, merge `#if` blocks.

Follow-up to 1db93bdb7c #22595

Closes #22613
2026-08-18 11:44:14 +02:00
Stefan Eissing
1d8f54823e
Happy Eyeballing v3: resolution delay of 25ms
After telemetry data from Mozilla reported the P99 DNS resolution
differences between A and AAAA responses to by 21ms, reduce curl's
resolution delay to 25ms.

What could possibly go wrong?

Closes #22612
2026-08-18 11:05:52 +02:00
Anton Karpov
05ddf5511a
headers: name the arguments the way the definitions name them
Eleven arguments are named one way in the header and another in the
definition. the compiler only checks types so nothing is broken, but the
header is what people read first, and then the name changes under them
in the source:

```
curl_dbg_malloc          size     ->  wantedsize
curl_dbg_calloc          n, size  ->  wanted_elements, wanted_size
curl_dbg_realloc         size     ->  wantedsize
curl_dbg_strdup          src      ->  source
r_freeaddrinfo           res      ->  cahead
my_get_line              fp, db   ->  input, buf
curl_slist_append_ccsid  l        ->  list
curl_version_info_ccsid  cid      ->  ccsid
curl_easy_setopt_ccsid   curl     ->  easy
```

Follow-up to df6014894b #20794

Closes #22550
2026-08-18 00:11:02 +02:00
Stefan Eissing
406edd036a
filter: change time reporting
Replace the QUERY filter methods for connect and appconnect time with a
new control CF_CTRL_REPORT_STATS that is triggered when a connect ends
(successful or not).

Filters in the connection can then report their statistics. Socket and
TLS filters do this only once. Subsequent CF_CTRL_REPORT_STATS will do
nothing.

This prevents timers to be reported twice in STARTTLS scenarios.

Fixes #22587 (again)
Closes #22596
2026-08-17 23:35:57 +02:00
Viktor Szakats
a01a24deaf
curlx_inet_pton: drop setting errno on error
Follow-up to bb406386d9 #22229

Closes #22607
2026-08-17 19:11:51 +02:00
Viktor Szakats
bb406386d9
curlx_inet_ntop: return CURLcode, drop setting errno
To simplify and to remove an exception where `errno` was reused to
return a socket error codes on Windows.

The error was used by one call site (`sockaddr2string()` in
`cf-socket.c`), but it was in practice always propagated as
`SOCKEAFNOSUPPORT` to callers.

Also:
- cf-socket: update 3 error messages to show `CURLcode` accordingly.
- if2ip: handle `curlx_inet_ntop()` error in `Curl_if2ip()`.
- dnsd: display `CURLcode` on two errors.

Follow-up to 39dec13ec0 #22170

Closes #22229
2026-08-17 18:41:31 +02:00
Stefan Eissing
8e2eced234
multi: initialisation order
When creating a multi handle, global_init() may not have been
invoked that. There is a lazy check for this in easy_init()
that trigger global_init().

Create the admin handle for a multi first, before any further
operations, so easy_init() can trigger a global_init() when
necessary.

Closes #22606
2026-08-17 15:05:39 +02:00
Daniel Stenberg
5406d2627c
urldata: drop four strings from the aptr struct
- 'rtsp_transport'

  There is no need to keep this data around once the RTSP request has been
  issued.

- 'accept_encoding'

  Only needed when creating the RTSP request.

- 'uagent'

  The header is generated on demand from set.str[STRING_USERAGENT]

- 'ref'

  Not necessary to keep around

Closes #22603
2026-08-17 14:03:44 +02:00
Stefan Eissing
c437d28c76
urldata: cleanups
- sockindex: int -> int8_t
- move connectdata members around for fun and profit
- remove data->state.current_speed as unused
- remove data->state.trailers_bytes_sent as unsed
- remove data->state.trailers_buf as unsed

The sockindex type change spread a little.

Closes #22604
2026-08-17 14:03:14 +02:00
Viktor Szakats
0c22fcffe3
config-riscos.h: delete handcrafted RISC OS config header, in favor of autotools
According to the content of the latest downloadable builds available at
(from 2022): https://www.riscos.info/packages/src/Network/, these builds
used autotools, not the handcrafted header. Also the handcrafted header
did not see an update (that I could find) since
0866c1b52d (2002-04-08), other than
source-wide maintenance updates.

Closes #22598
2026-08-17 00:00:14 +02:00
Viktor Szakats
5b9946a106
curl_threads: always use native threads/mutex on Windows
Syncing with build systems, which already enforce this.

Closes #22593
2026-08-16 12:16:57 +02:00
Viktor Szakats
1db93bdb7c
config-win32.h: limit use to MSVC IDE Project builds
This is the only purpose it's maintained for.

Drop mingw-w64 and other logic falling outside of VS2010-2013 needs.

mingw-w64/MSVC platform differences keep being maintained/documented as
part of the CMake pre-fill logic in `CMake/win32-cache.cmake`.

Follow-up to ba8752e556 #12224

Closes #22595
2026-08-16 10:08:33 +02:00
Stefan Eissing
787cbd2033
multi: shrink expire timer indices
The enum `exire_id` fits easily into a uint8_t. Use that type for
storing expire timeout list indices.

Closes #22591
2026-08-15 22:35:20 +02:00
hunterinvariants
c7c42afab9
file: support directory listing on Windows
Closes #22577
2026-08-15 11:56:25 +02:00
Stefan Eissing
ebc0fbc0e8
connect: only set connect timer on first socket
Only collect connect/appconnect timer stats on the first socket.

Fixes #22587
Closes #22592
Reported-by: GLaDOS-418 on github
2026-08-15 11:55:38 +02:00
Stefan Eissing
3d6d93a6be
multi: timeout improvements
- Move expire timeout code from multi into splay.c
- keep a "time_base" timestamp to calculate timediff_t for
  actual timeout values. Unfortunately this means our
  timeouts will go wrong after ~500,000 years of continuous
  operations...
- use timediff_t as key in splay instead of curltime
- use timediff_t in transfers expire times instead of curltime
- re-comment splay.c for better understanding how it works
- replace splay nodes double-linked "same" list with a single link,
  we almost never have duplicate keys
- keep transfer `mid` in splay nodes instead of the transfer pointer
- keep registered bit in splay node for tracking instead of separate
  bit in transfer
- adapt unit1309.c to changes in timediff_t and mid

Closes #22584
2026-08-14 22:39:41 +02:00
Daniel Stenberg
fe703df949
lib: optimize struct layouts for reduced memory usage
struct SingleRequest tweaks

- 'upgr101' from enum upgrade101 => 'unsigned char', saves three bytes
- made some 'unsigned char' => uint8_t
- moved 'io_flags' to fill a hole on 64-bit arch

struct UserDefined tweaks

- Sort the fields by size. Larger to smaller. Helps avoding holes.
- httpsig_algorithm moved
- FTP uint8_t fields moved
- new_file_perms moved
- rtspreq moved
- sort fields on size

- urldata: drop 'struct Curl_data_priority'

  It only had a single struct member 'weight'. Use that directly instead
  to save indirections and struct alignments. Move field for size order.

- urldata: move the RTSP fields in the UrlState struct to be ordered by
  size

struct PureInfo tweaks

- make 'pxcode' a uint8_t
- move 'conn_protocol' to fill a hole
- sort 'struct PureInfo' fields by size

Closes #22585
2026-08-14 16:14:24 +02:00
Stefan Eissing
7103a93b05
connections: use admin handles only for maintenance
Maintenance tasks like connection upkeep, liveliness checks and cache
eviction must only run on an admin handle, not the application transfer
from the calling context.

Then application transfers will get only attached to the connections
they actually work on. This makes `data->state.recent_conn_id`
meaningful for checks if a subsequent address is finding the previous
connection again.

One thing led to another:
- add Curl_get_admin(data), to obtain an admin handle for
  an application handle, inheriting some properties for
  connection operation.
- rename `Curl_easy *data` parameter to `Curl_easy *admin`
  where only admin handles should be passed. Add DEBUGASSERTs
  in the called function.
- rename `Curl_conn_terminate()` to `Curl_conn_close()`
  because this makes connections enter the shutdown close
  where possible.
- rename `Curl_cshutdn_terminate()` to `Curl_conn_terminate()`
  since this definitely kills the connection and does not
  involve a `cshutdn` instance.
- add Curl_share_lock_share(), Curl_share_unlock_share()
  so it possible to operate on a share without the passed
  easy handle having the share set.
  This catches a case where a shared needed to be locked
  but was not before. Adjust test1554 results.

Fixes #22567
Reported-by: cybertron10 on github
Closes #22572
2026-08-14 14:01:21 +02:00
Stefan Eissing
6e9880366f
Revert "uint-bset: add slot0 member"
This reverts commit 743096a496.

Closes #22581
2026-08-14 13:41:03 +02:00
Daniel Stenberg
554efab7f6
multi: drop the assert from large expires
Triggers the fuzzers

Closes #22582
2026-08-14 13:39:42 +02:00
Daniel Stenberg
a3aaca10d9
multi: cap expire times to INT_MAX internally
When the time-out value is passed to the outside world it needs to fit
in a signed 32-bit variable (on Windows and 32-bit architectures)
anyway. Also, this is 3.5 weeks and we should not knowingly set timeouts
that long anyway.

The previous cap introduced in 3089e7eec8 was only partial.

Closes #22579
2026-08-14 10:39:47 +02:00
Thomas Chauchefoin
68b5e60138
dict: avoid busy-loop in sendf() when the socket is not writable
Curl_xfer_send() reports CURLE_AGAIN as a successful zero-byte send, so
the retry loop spun at 100% CPU and ignored the timeout when the peer
stopped draining. Wait for writability and check the remaining time
between retries.

Closes #22576
2026-08-14 10:12:30 +02:00
Daniel Stenberg
ca26e728a6
conncache: don't assume curl_off_t increment wrap-around
In the totally unlikely event that next_easy_id would ever wrap, avoid
undefined behavior. It is a signed type.

Also: update the related comment in urldata.h that mentioned LONG_MAX
but is nowadays CURL_OFF_T_MAX

Closes #22569
2026-08-13 14:43:08 +02:00
Daniel Stenberg
6a6edec2c6
multihandle: move two struct fields
To avoid holes on 64-bit architectures.

Closes #22565
2026-08-13 08:28:23 +02:00
Daniel Stenberg
3089e7eec8
multi: hold timeout values in 'int' instead of 'long'
Since this code needs to work (identically) on systems with 32 bit longs
anyway, this might just as well always use 32 bit to save space and make
the code work the same everywhere.

Closes #22564
2026-08-13 00:00:47 +02:00
Stefan Eissing
e9b291cf9b
header api: add guards
Add API guards for curl_easy_header and curl_easy_nextheader.

urldata.h: remove prevhead member as not used

Closes #22530
2026-08-12 21:56:48 +02:00
Stefan Eissing
743096a496
uint-bset: add slot0 member
Add a fixed slot0 member for uint32_bset to have no allocations for
sizes < 64. This is a common use case for curl_easy_perform().

Closes #22561
2026-08-12 21:55:41 +02:00
Stefan Eissing
507ee5d792
progress: fix progress meter update to run every second again
Closes #22562
2026-08-12 21:54:42 +02:00
Stefan Eissing
1a17959fc7
url: fix negotiate/ntlm connection reuse
Reorder logic when looking for matching connections. Check candidate
Negotiate/NTLM state first. Require same "input" parameters when
connection is already authenticated. Same for proxy.

Deny connection reuse for empty usernames for NTLM/Negotiate using
connections.

Reported-by: Martin Dukek
Closes #22528
2026-08-12 16:46:01 +02:00
Viktor Szakats
8a8ff47b63
tidy-up: C and CI
- drop redundant casts for `CURL_UNCONST()` pointers (Windows).
- GHA/linux: delete redundant/dupe `-g` C flag in memory sanitizer job.
  Spotted-by: Daniel Stenberg
- examples/http2-upload: drop local macro.
- examples/http2-upload: drop leading underscore from union name.
- examples/http2-upload: drop interim macro.
- tests/server/util: reapply patch lost in a rebase.
- sync `main()` declarations across the codebase.

Closes #22559
2026-08-12 15:42:54 +02:00
Stefan Eissing
35843dd635
progress: cleanup, less memory
Keep only a single `start` time and calculate the rest in delta
microseconds since then. Separate timestamps and durations into separate
sub-structures for clarity.

remove progress.t_acceptdata
It was recorded in FTP accept but never used anywhere.

Closes #22547
2026-08-12 14:51:06 +02:00
Daniel Stenberg
fbfb2499f0
keylog: add a random size argument to Curl_tls_keylog_write()
To allow the function to verify that the buffer is large enough. Avoids
possible future internal mishaps.

Closes #22560
2026-08-12 14:33:01 +02:00
Daniel Stenberg
d064bc2adb
thrdqueue: drop name strdups from Curl_thrdq_create
The only usage of the thread queue and pool is for "DNS" which is a
static string. No point in strdup'ing it (twice). Future users are
*likely* to also used fixed strings, otherwise we revert this change
when dynamic names are introduced.

Reported-by: Max Dymond
Closes #22555
2026-08-12 14:17:01 +02:00
Daniel Stenberg
eae88a7473
urlapi: avoid dedotdotify() if possible
The dedotdotify() function that removes ./ and ../ sequences from paths
juggles memory and is slow. Now needs_dedotdot() is called first to
determine if the removal process is necessary and otherwise avoids doing
it. Avoids unnecessary memory operations.

Adjusted unit test 1395 accordingly because now a lot of input strings
return NULL for "no change necessary".

Suggested-by: Max Dymond

Closes #22557
2026-08-12 13:43:13 +02:00
Viktor Szakats
da04aa96ab
tidy-up: comments and formatting
Closes #22558
2026-08-12 13:32:22 +02:00
Alhuda Khan
f5378b88a9
content_encoding: exact-match the identity transfer-coding token
Verified by test 2119

Closes #22541
2026-08-11 17:36:19 +02:00
hunterinvariants
419f6404d4 schannel: reuse the send buffer
- Reuse a buffer for schannel_send instead of allocating and freeing a
  buffer for every send.

Closes https://github.com/curl/curl/pull/22540
2026-08-11 03:14:04 -04:00