Commit Graph

16407 Commits

Author SHA1 Message Date
Viktor Szakats
8968a68eba
libssh: fix -Wsign-compare in 32-bit builds by dropping a redundant check
Follow-up to 8c8eeba522 #21214 (wrong silencing)
Follow-up to c049c37acd #18989 (add redundant check)
Follow-up to c988ec9f41 #9328 (make check fail)
Follow-up to 44a02d2532 #9324 (add original check)

Closes #21225
2026-04-05 15:23:02 +02:00
Daniel Stenberg
2e5d219205
sendf: fix CR detection if no LF is in the chunk
When doing line ending conversions, and a chunk contains no '\n', the
function returned early without updating prev_cr to reflect the last
byte. It could then lead to CRLFs sequences not get converted when
occuring right on the boundary border.

Found by Codex Security

Closes #21221
2026-04-04 22:32:54 +02:00
Daniel Stenberg
741ee57375
doh: remove superfluous doh_req check
It has already been checked previously in the function.

Spotted by CodeSonar

Closes #21216
2026-04-04 17:10:37 +02:00
Daniel Stenberg
6d6d81e393
url: set default upload flags to CURLULFLAG_SEEN
As documented. Not doing this was a regression.

Follow-up to 6758aa722d

Reported by Codex Security

Closes #21217
2026-04-04 17:07:22 +02:00
Viktor Szakats
8c8eeba522
libssh: fix -Wsign-compare in 32-bit builds
Seen with mingw-w64 i686 gcc 15.2.0 (mingw32):
```
D:/a/curl/curl/lib/vssh/libssh.c: In function 'myssh_in_SFTP_QUOTE_STAT':
D:/a/curl/curl/lib/vssh/libssh.c:1664:13: error: comparison of integer expressions
  of different signedness: 'time_t' {aka 'long int'} and 'unsigned int' [-Werror=sign-compare]
 1664 |     if(date > UINT_MAX)
      |             ^
cc1.exe: all warnings being treated as errors
```
Ref: https://github.com/curl/curl/actions/runs/23966805891/job/69908216152

Cherry-picked from #21199

Closes #21214
2026-04-04 13:55:16 +02:00
Daniel Stenberg
1bf663e32f
dnscache: fix locking for negative caching
Reported-by: Izan on hackerone
Closes #21209
2026-04-03 22:27:59 +02:00
Daniel Stenberg
e65ba1bd34
hsts: make the HSTS read callback handle name dupes
Now the logic for handling name duplicates and picking the longest
expiry and strictest subdomain is the same for the callback as for when
reading from file.

Also strip trailing dots from the hostname added by the callback.

A minor side-effect is that the hostname provided by the callback can
now enable subdomains by starting the name with a dot, but we discourage
using such hostnames in documentation.

Amended test 1915 to verify.

Closes #21201
2026-04-02 18:01:20 +02:00
Stefan Eissing
99d5b90878
asyn-thrdd: item cleanup using resolv_id
Now that we support multiple async operations at the same transfer,
fix the thread queue cleanup to match not only the mid but also the
resolv_id.

Found by Codex Security

Closes #21202
2026-04-02 13:15:53 +02:00
Stefan Eissing
33e43985b8
url: improve connection reuse on negotiate
Check state of negotiate to allow proper connection reuse.

Closes #21203
2026-04-02 13:14:29 +02:00
Daniel Stenberg
b27e828b93
url: init req.no_body in DO so that it works for h2 push
req.no_body was only initialized in Curl_connect, while HTTP/2 server
push adds a duplicated handle via Curl_multi_add_perform and calls
Curl_init_do with conn==NULL, never invoking Curl_connect.

Verify it by amending test 1620

Found by Codex Security

Closes #21194
2026-04-02 10:50:23 +02:00
Daniel Stenberg
93e80c75b4
hsts: accept 10K entries in the list
Up from 1K.

Reduces the risk that someone could flush the list by tricking a user to
do many transfers to new hostnames.

Document the limit.

Follow-up to 03a792b186

Closes #21200
2026-04-02 10:22:35 +02:00
Daniel Stenberg
d888a53e14
libssh: path length precaution
Make sure the string is non-zero before indexing it -1. Right now, the
path is always non-zero length so this is more for (future) safety
reasons.

Closes #21193
2026-04-02 09:55:25 +02:00
Viktor Szakats
0b06b944fe
spelling: fix typos
Closes #21198
2026-04-01 22:50:12 +02:00
Viktor Szakats
0df6c01db3
tidy-up: rename Curl_safefree()/tool_safefree() to curlx_safefree()
To sync names for the same macro logic between lib and src, and to move
it to the curlx namespace, to match `curlx_free()` that it's calling.

Closes #21151
2026-04-01 19:53:53 +02:00
Stefan Eissing
2b3dfb4ad4
lib: make resolving HTTPS DNS records reliable:
- allow to specify when they are wanted on starting a resolve
- match dns cache entries accordingly. An entry which never
  tried to get HTTPS-RRs is no answer for a resolve that wants
  it.
- fix late arrivals of resolve answers to match the "async"
  records that started them - if it still exists.
- provide for multiple "async" resolves in a transfer at the
  same time. We may need to resolve an IP interface while the
  main connection resolve has not finished yet.
- allow lookup of HTTPS-RR information as soon as it is
  available, even if A/AAAA queries are still ongoing.

For this, the "async" infrastructure is changed:

- Defined bits for DNS queries `CURL_DNSQ_A`, `CURL_DNSQ_AAAA`
  and `CURL_DNSQ_HTTPS`. These replace `ip_version` which says
  nothing about HTTPS.
  Use them in dns cache entries for matching.
- enhance the `async->id` to be a unique `uint32_t` for
  resolves inside one multi. This is weak, as the id may
  wrap around. However it is combined with the `mid` of
  the easy handle, making collisions highly unlikely.
  `data->state.async` is only accessed in few places where
  the mid/async-id match is performed.
- vtls: for ECH supporting TLS backends (openssl, rustls, wolfssl),
  retrieve the HTTPS-RR information from the dns connection filter.
  Delay the connect if the HTTPS-RR is needed, but has not
  been resolved yet.

The implementation of all this is complete for the threaded
resolver. c-ares resolver and DoH do not take advantage of
all new async features yet. To be done in separate PRs.

Details:

c-ares: cleanup settings and initialisation. Any ares channel
is only being created on starting a resolve and propagating
operations in setopt.c to the channel are not helpful.

Changed threaded+ares pollset handling so that they do not
overwrite each others `ASYNC_NAME` timeouts.

Add trace name 'threads' for tracing thread queue and
pool used by threaded resolver.

Closes #21175
2026-04-01 15:36:31 +02:00
Daniel Stenberg
03a792b186
HSTS: cap the list at 1,000 entries
Avoid never-ending growth.

When adding more entries, it now deletes the first entry in the list,
which is the oldest added entry still held in memory. I decided to avoid
a Least Recently Used concept as I suspect with a list with this many
entries most entries have not been used, and we don't save the timestamp
of recent use anyway.

The net effect might (no matter what) be that the removed entry might
feel a bit "random" in the eyes of the user.

Verify with test 1674

Ref #21183
Closes #21190
2026-04-01 14:38:41 +02:00
Daniel Stenberg
0805ec043e
altsvc: cap the list at 5,000 entries
Avoid never-ending growth.

When adding more entries, it now deletes the first entry in the list,
which is the oldest added entry still held in memory. I decided to avoid
a Least Recently Used concept as I suspect with a list with this many
entries most entries have not been used, and we don't save the timestamp
of recent use anyway.

The net effect might (no matter what) be that the removed entry might
feel a bit "random" in the eyes of the user.

Verify with test 1669.

Reported-by: Geeknik Labs
Fixes #21183
Closes #21189
2026-04-01 12:05:47 +02:00
Daniel Stenberg
c1963e2d2c
altsvc: drop the prio field from the struct
The value is not used for anything, no point in keeping it in memory.

Closes #21188
2026-04-01 11:06:43 +02:00
Daniel Stenberg
11609c3d45
alt-svc: skip expired entries read from file
Extend test 1654 to verify

Closes #21187
2026-04-01 10:56:11 +02:00
Daniel Stenberg
4478a10f0d
hsts: skip expired HSTS entries read from file
Extend test 780 to verify

Closes #21186
2026-04-01 10:49:26 +02:00
Daniel Stenberg
8e8bdd3604
cookie: fix rejection when tabs in value
A previous refactor changed the TAB check so that the octet could be
accepted in the 'path', which would cause an invalid line in the saved
cookie file so not possible to read the cookie back. Not terrible
because the path cannot contain a raw tab anyway so it would never match
anyway.

Add test 1685 to verify

Reported-by: Izan on hackerone

Closes #21185
2026-04-01 10:45:05 +02:00
Daniel Stenberg
1ec912d292
http: refactor http_on_response into sub functions
Reduces complexity.

Closes #21172
2026-03-31 23:53:45 +02:00
Daniel Stenberg
6eab0a42e3
md5: fix large size handling
Follow-up to dd7fcd581f

Closes #21180
2026-03-31 17:53:03 +02:00
Daniel Stenberg
dd7fcd581f
lib: accept larger input to md5/hmac/sha256/sha512 functions
Avoid unchecked data conversions from size_t to unsigned int.

Reported-by: James Fuller
Closes #21174
2026-03-31 17:19:56 +02:00
Daniel Stenberg
9b36748938
http2: return error on OOM in push headers
Reported-by: M42kL33 on hackerone
Bug: https://hackerone.com/reports/3636044
Closes #21171
2026-03-31 08:59:07 +02:00
Viktor Szakats
e49190f9f3
cf-https-connect: silence -Wimplicit-int-enum-cast with HTTPS-RR + clang 21 (reapply)
Reapply: e09a7b83d6 #21057

Also:
- enable HTTPS-RR by default in curl-for-win to test it with clang 21.
  Ref: dc65c449f3

Follow-up to 335dc0e3c5 #21027

Closes #21167
2026-03-31 03:32:36 +02:00
Viktor Szakats
ce6c441cf2
build: drop redundant HAVE_PTHREAD_H guard
Prior to this patch code used either `HAVE_PTHREAD_H`, or
`HAVE_THREADS_POSIX`, or both, to decide if POSIX Threads support is
present. In effect requiring both to be defined for a consistent build.

Drop detecting and guarding for `pthread.h`, and assume it present when
`HAVE_THREADS_POSIX` is set.

OS/400 had `HAVE_PTHREAD_H` set, but not `HAVE_THREADS_POSIX`, which
possibly left threading disabled in most sources.

Ref: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/pthread.h.html
Ref: 930f2e8227 #21144

Closes #21158
2026-03-30 18:57:07 +02:00
Daniel Stenberg
7deed5bb55
wolfssl: fix build without TLS 1.3 support
Follow-up to: eac64c1879

Closes #21161
2026-03-30 18:50:02 +02:00
Stefan Eissing
8deaf04feb
fopen: for temp files, inherit permissions only for owner
When creating a temp file in order to later replace an original, copying
over the existing permissions can not be considered safe when the user
running libcurl is not the owner of the existing file.

Closes #21092
2026-03-30 18:39:12 +02:00
Daniel Stenberg
eac64c1879
wolfssl: refactor Curl_wssl_ctx_init into sub functions
Reduce complexity. It was at complexity 60, with is the current max
allowed. After this, the worst in wolfssl.c is at 29.

Closes #21128
2026-03-30 16:46:53 +02:00
Kaixuan Li
2c26cea5ec
socks: add assertion for hostname length in SOCKS5 connect
socks5_req0_init() rejects hostnames longer than 255 bytes, but the
later cast to unsigned char in socks5_req1_init() has no local
indication that it is safe. Add a DEBUGASSERT and comment to document
the invariant and guard against future refactoring.

Closes #21157
2026-03-30 16:13:24 +02:00
Greg Kroah-Hartman
fb6925c243
socks: reject zero-length GSSAPI/SSPI tokens from proxy
A "broken" SOCKS5 proxy can send an invalid length of the encryption
token, which could cause malloc(0) to be called, which is a "platform
can do what it wants" potential problem.

Resolve this by explicitly checking the length and rejecting the invalid
token before ever attempting to allocate any memory.

Closes #21159
2026-03-30 16:07:06 +02:00
Viktor Szakats
930f2e8227
build: drop duplicate pthread.h includes
Already included from `curl_setup.h`.

Closes #21144
2026-03-30 13:46:14 +02:00
Viktor Szakats
3c72928471
build: drop redundant USE_QUICHE guards
When used together with `USE_OPENSSL`. `USE_QUICHE` always implies
`USE_OPENSSL`.

Also: merge two (now identical) `#if` blocks in `openssl.c`.

Closes #21135
2026-03-30 13:46:14 +02:00
Viktor Szakats
20b18a43f6
src: drop detecting and redefining system symbol ftruncate
Introduce `toolx_ftruncate()` macro and map it to existing replacements
for non-mingw-w64 Windows and DJGPP, or to `ftruncate` otherwise.

Follow-up to 6041b9b11b #21109

Closes #21130
2026-03-30 13:46:14 +02:00
Stefan Eissing
335dc0e3c5
cf-dns: connection filter for DNS queries
New connection filter `cf-dns` that manages DNS queries. If hands
out addresses and HTTPS-RR records to anyone interested. Used by
HTTPS and IP happy eyeballing.

Information may become available *before* the libcurl "dns entry"
is complete, e.g. all queries have been answered. The cf-ip-happy
filter uses this information to start connection attempts as soon
as the first address is available.

The multi MSTATE_RESOLVING was removed. A new connection always
goes to MSTATE_CONNECTING. The connectdata bit `dns_resolved`
indicates when DNS information is complete. This is used for
error reporting and starting the progress meter.

Removed dns entries `data->state.dns[i]`, as the `cf-dns` filter
now keeps the reference now.

Many minor tweaks for making this work and pass address information
around safely.

Closes #21027
2026-03-30 13:28:38 +02:00
Viktor Szakats
89741958e8
cmake: use AIX built-in variable (with CMake 4.0+)
Also keep the old method for compatibility with CMake <4.0.

Ref: https://cmake.org/cmake/help/v4.0/variable/AIX.html

Closes #21134
2026-03-30 13:05:17 +02:00
Viktor Szakats
89dbe84fdf
curl_ngtcp2: extend and update callbacks for 1.22.0+
Fixing:
```
lib/vquic/curl_ngtcp2.c:880:1: error: missing field 'recv_stateless_reset2' initializer [-Wmissing-field-initializers]
  880 | };
      | ^
```

Also:
- GHA/http3-linux: bump to ngtcp2 v1.22.0.

Refs:
https://github.com/ngtcp2/ngtcp2/releases/tag/v1.22.0
b7bfe41db8
https://github.com/ngtcp2/ngtcp2/pull/2035

Closes #21152
2026-03-30 10:59:38 +02:00
Viktor Szakats
f0f0a7f7d6
boringssl: fix more coexist cases with Schannel/WinCrypt
By moving the coexist workaround from vtls/openssl.c to vtls/openssl.h.
This way it also applies to vtls.c (and possibly other sources including
`vtls/openssl.h`), which may need it in unity builds before BoringSSL
header `openssl/ssl.h` pulling in the conflicting symbols and causing
conflicts otherwise.

Seen with build config:
```
-DCURL_USE_SCHANNEL=ON -DCURL_USE_OPENSSL=ON
-DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30
```

Fixing:
```
In file included from _cm-win-boringssl/lib/CMakeFiles/libcurl_object.dir/Unity/unity_5_c.c:7:
In file included from lib/vtls/vtls.c:54:
In file included from lib/vtls/openssl.h:33:
In file included from /path/to/boringssl/_x64-win-ucrt/usr/include/openssl/opensslv.h:18:
In file included from /path/to/boringssl/_x64-win-ucrt/usr/include/openssl/crypto.h:18:
/path/to/boringssl/_x64-win-ucrt/usr/include/openssl/base.h:293:29: error: expected ')'
  293 | typedef struct X509_name_st X509_NAME;
      |                             ^
/path/to/llvm-mingw/x86_64-w64-mingw32/include/wincrypt.h:1515:29: note: expanded from macro 'X509_NAME'
 1515 | #define X509_NAME ((LPCSTR) 7)
      |                             ^
[...]
```

Ref: 2a92c39a21 #20567

Closes #21136
2026-03-28 15:52:41 +01:00
Viktor Szakats
9b01f73ac2
keylog.h: replace literal number with macro in declaration
Also syncing with the defintion.

Closes #21141
2026-03-28 15:51:04 +01:00
Viktor Szakats
31ec67651a
keylog: drop unused/redundant includes and guards
Closes #21137
2026-03-28 12:20:03 +01:00
Daniel Stenberg
ff678be69a
libssh: propagate error back in SFTP function
The myssh_in_SFTP_READDIR_BOTTOM() function would not store the error
code correctly thus it could be ignored and missed when an error was
returned at that particular moment.

Follow-up to 3c26e6a896

Found by Codex Security

Closes #21122
2026-03-27 16:12:51 +01:00
Daniel Stenberg
86b39c2226
transfer: clear the URL pointer in OOM to avoid UAF
Since the pointer can be extracted with CURLINFO_EFFECTIVE_URL later it
must not linger pointing to freed memory.

Found by Codex Security

Closes #21123
2026-03-27 15:56:12 +01:00
Daniel Stenberg
28fbf4a87d
multi: fix connection retry for non-http
non-HTTP protocols no longer retry after connection reuse failures
because multi_follow() now requires a handler->follow callback that is
NULL for those protocols. Provide a fallback for plain retries.

Follow-up to 1213c31272

Spotted by Codex Security

Closes #21121
2026-03-27 15:54:22 +01:00
Stefan Eissing
2e8c922a89
http2: prevent secure schemes pushed over insecure connections
When assembling the URL of a pushed resource over a not-secured
connection, require the scheme to be known and not secure.

Reported-by: xkilua on hackerone

Closes #21113
2026-03-27 14:23:29 +01:00
Viktor Szakats
c025082967
openssl: fix build with 4.0.0-beta1 no-deprecated
```
lib/vtls/openssl.c:4238:22: error: ‘SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED’ undeclared (first use in this function); did you mean ‘SSL_R_TLS_ALERT_CERTIFICATE_EXPIRED’?
 4238 |           (reason == SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED))) {
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                      SSL_R_TLS_ALERT_CERTIFICATE_EXPIRED
lib/vtls/openssl.c:4238:22: note: each undeclared identifier is reported only once for each function it appears in
```
Ref: https://github.com/curl/curl/actions/runs/23641366299/job/68863072427#step:24:189

Cherry-picked from #21118

Closes #21119
2026-03-27 12:05:51 +01:00
Daniel Stenberg
10d5177984
request: reset resp_trailer in new requests
Otherwise the trailer state lingers on into subsequent requests.

Follow-up to 29610e5f3d

Spotted by Codex Security

Closes #21112
2026-03-27 09:51:34 +01:00
Daniel Stenberg
248b92939a
cf-socket: avoid low risk integer overflow on ancient Solaris
Spotted by Codex Security

Closes #21111
2026-03-27 09:34:42 +01:00
Daniel Stenberg
b71973c115
tool: fix memory mixups
memory allocated by libcurl must be freed with curl_free() and vice versa,
memory allocated by the tool itself must be freed with curlx_free().

- dynbuf: free libcurl data with curl_free()
- tool_operate: make sure we get URL using the right memory
- tool_operhlp: free libcurl memory with curl_free()
- tool_operate: free curl_maprintf() pointer with curl_free
- var: data from curlx_base64_decode needs curlx_free
- tool_operate: fix memory juggling in etag handling
- tool_cb_hdr: fix memory area mixups
- tool_operate: another mixup in etag management
- tool_cb_hdr: more memory mixup fixes
- tool_cfgable.c: document some details
- tool_help: show global-mem-debug in -V output

Closes #21099
2026-03-27 08:10:32 +01:00
Daniel Stenberg
e1fdbdd16f
hsts: when a dupe host adds subdomains, use that
Otherwise a weaker earlier entry is allowed to override a later more
restrictive one.

Add test 1638 to verify.

Closes #21108
2026-03-26 23:27:24 +01:00