Commit graph

16719 commits

Author SHA1 Message Date
Stefan Eissing
73daec6620
lib: transfer origin and proxy handling
Add `data->state.origin` as the origin the transfer is sending the
current request to/gets the response from. Use it for request specific
properties like authentication, hsts and cookie handling, etc.

Unless talking to a forwarding HTTP proxy (e.g. not tunneling),
`data->state.origin` and `conn->origin` are the same.

With a forwarding HTTP proxy in play, `conn->origin` is set to
`conn->http_proxy.peer` and `conn->bits.origin_is_proxy` (a new bit) is
set.

Remove the connection bits, now replaced with:

* `conn->bits.socksproxy` -> `conn->socks_proy.peer`
* `conn->bits.httpproxy` -> `conn->http_proy.peer`
* `conn->bits.proxy` -> `(conn->socks_proy.peer || conn->http_proy.peer`)
* `conn->bits.tunnel_proxy` -> (`conn->http_proy.peer && !conn->bits.origin_is_proxy`)
* `(conn->bits.httpproxy && !conn->bits.tunnel_proxy)` -> `conn->bits.origin_is_proxy`

Rename `noproxy.[ch]` to `proxy.[ch]`. Move the connection proxy setup
code from `url.c` to `proxy.c`.

Remove `data->info.conn_remote_port` as no one uses it.

Add test_40_02b for a SOCKS connection to a forwarding HTTPS proxy.

Update internal documentation about peers and creds.

Closes #21967
2026-06-12 23:52:00 +02:00
Viktor Szakats
879a1514c3
socket: introduce SOCK_EAGAIN() and use it
To contain the logic of checking for both `EWOULDBLOCK` and/or `EAGAIN`
depending on platform/availability. Also to avoid checking for both if
they mapp to the same value, and to avoid PP guards around use.

This also ensures `EAGAIN` is consistently not checked on Windows, where
headers defined it, but `SOCKERRNO` never returns it, because curl maps
it to `WSAGetLastError()`.

If they map to the same value, checking them both in an `if` expression
trips GCC warning `-Wlogical-op` (the same way it triggers duplicate
case value error in `switch`).

Also:
- replace two `switch()` statements with the new macro.
- tests/server/sws: make two outliers use the new macro that were only
  checking for `EWOULDBLOCK` before this patch, in `connect_to()`.
- move variables to the left-side of expressions, where missing.
- rustls: use a variant of this macro that uses raw `EWOULDBLOCK`.
  Tried tracing it back to the origins, but I couldn't figure out if
  this is working as expected on all supported Windows versions in
  Rust. It seems to be using `GetLastError()`, according to
  https://docs.rs/system_error/0.2.0/system_error/, which would be
  probably incorrect.

Notes:
- it's probably a good idea to assign `SOCKERRNO` to a variable before
  passing it to this macro.

Cherry-picked from #21893

Closes #21992
2026-06-12 23:27:23 +02:00
Stefan Eissing
7d8c68adbe schannel: fix https proxy for client cert and certinfo
When schannel operates in front of a proxy, it needs to use the proxy
ssl configs, not the transfers ones. Choose the configs as it is done in
other TLS backends.

Prior to this change the client cert for the destination was mistakenly
also used as the client cert for the proxy.

Prior to this change the proxy server certificate info was mistakenly
saved as the destination cert info. However, if the destination was a
TLS connection, the real destination cert info would overwrite the
proxy cert info. libcurl currently does not support proxy server cert
info AFAICT (see discussion in #21986).

Closes https://github.com/curl/curl/pull/21986
2026-06-12 14:21:10 -04:00
Viktor Szakats
4f53234309
telnet: fix old copy-paste typo in variable name
This code lacks tests, though we agreed it looks plausible enough to
merge it based on surrounding code. Even though this line has been
present for a long time. If you use this code, please report any results
or issues.

Reported by GitHub Code Quality

Follow-up to ae1912cb0d

Closes #21979
2026-06-12 16:03:32 +02:00
Darren Banfi
982e2e8c75
AmigaOS: curl_setup.h avoid explicit_bzero with clib2
clib2 defines __NEWLIB__ after its system headers are included, but it
does not provide explicit_bzero().

curl therefore selects the explicit_bzero() path and fails to build with
m68k-amigaos-gcc:

```
../lib/curl_setup.h:1650:35: error: implicit declaration of function 'explicit_bzero' [-Werror=implicit-function-declaration]
 1650 | #define curlx_memzero(buf, size)  explicit_bzero(buf, size)
      |                                   ^~~~~~~~~~~~~~
curlx/strdup.c:115:5: note: in expansion of macro 'curlx_memzero'
  115 |     curlx_memzero(buf, size);
      |     ^~~~~~~~~~~~~
```

Excluding __CLIB2__ from the generic __NEWLIB__ branch makes curl use
its existing portable curlx_memzero() fallback. The full AmigaOS build
then completes successfully.

I've tested the following on Amiga OS 3.2.3 with this patch and latest
build.

- HTTP and HTTPS transfers
- AmiSSL certificate handling
- redirects
- downloads and file output
- timeout handling with the expected exit code 28
- repeated execution with clean exits
- no crashes or regressions observed

Follow-up to 066478f634 #21598

Closes #21989
2026-06-12 14:44:10 +02:00
Viktor Szakats
bcb2890c6f
telnet: fix error message typos
Spotted by GitHub Code Quality

Closes #21976
2026-06-11 22:09:47 +02:00
Viktor Szakats
e35ba09f47
tidy-up: add spaces around equal operators where missing
Found via regex search: `=[^~>= ]`

Closes #21975
2026-06-11 19:52:01 +02:00
Viktor Szakats
2a606c68fa
tidy-up: miscellaneous
- GHA/windows: drop redundant double-quotes.
- CMake/PickyWarnings: improve/shorten comment.
- INTERNALS: fix typo in LibreSSL release date.
- drop redundant parentheses from single variables and sole `#if`
  expressions.
- cf-ip-happy: fix missing space from error string.
- telnet: fix parentheses in commented PP code.
- lib1922: fix typo test output text.
- smbserver: unfold lines.
- smbserver: use f-string.
- smbserver: initialize binary string as b``.
- fix typos in comments.

Closes #21972
2026-06-11 19:48:07 +02:00
sourceturner
04a85a1d38
asyn-thrdd: add IPv6 guards
It seems that the usual '#ifdef USE_IPV6' guards have been overlooked in
lib/asyn-thrdd.c.

This commit makes sure that the code compiles if IPv6 is not available.

Closes #21881
2026-06-11 19:33:41 +02:00
Daniel Stenberg
7f45bb8f5b
http_digest: return better error
It is not a content encoding error.

Found by the GitHub AI thing.

Closes #21969
2026-06-11 16:06:40 +02:00
Daniel Stenberg
f763847982
cf-ip-happy.c: minor comment typo 2026-06-11 15:44:28 +02:00
Daniel Stenberg
2b336e6b73
content_encoding: fix non-last chunked rejection
Even when two 'chunked' are listed and neither is the last encoding the
transfer is rejected.

Verified by test 1722 and 1723

Reported-by: violet12331 on hackerone
Closes #21966
2026-06-11 13:21:09 +02:00
Daniel Stenberg
9cf6b70ad7
multi: remove a stale comment
It tricks humans and AIs alike.

Closes #21961
2026-06-11 10:11:15 +02:00
Stefan Eissing
8a867c2062
h3proxy: no stream userdata
Do not set the easy handle opening a proxy tunnel as userdata on the
stream. The ease handle might go out of scope long before the tunnel
stream is closed.

Closes #21962
2026-06-11 10:07:42 +02:00
Stefan Eissing
946306b3e5
cf-ip-happy: update documentation
Reported-by: correctmost on github
Fixes #21957
Closes #21959
2026-06-11 10:06:09 +02:00
Stefan Eissing
30c9c79cf8
cf-socket: make Curl_addr2string static
Move as sockaddr2string() into cf-socket.c where its only callers are.

Mark as UNITTEST for unit1609.

Move "struct Curl_sockaddr_ex" into sockaddr.h, so connect.h and
cf-socket.h can be included without all the system headers needed.

Closes #21946
2026-06-11 08:15:31 +02:00
alhudz
7ec25148c0
digest: flush proxy state on proxy or credential change
Closes #21951
2026-06-11 08:13:20 +02:00
Daniel Stenberg
a6971ce90a
connect: turn conn_get_first_origin into static
This function is only used within this source file.

Closes #21948
2026-06-10 22:58:42 +02:00
Viktor Szakats
97aed9c960
tidy-up: drop stray comparisons with literal zero
Drop from:
- strcmp, strcmpi, strncmp, memcmp, lstat, getrlimit, setrlimit, fseek,
  fstat
- autotools detection snippets.
- smooth-gtk-thread: simplify `!var != 0` expression.

Closes #21947
2026-06-10 15:15:54 +02:00
Viktor Szakats
2f3fa479dd
build: enable -Wformat-signedness, fix issues found
Adjust code to avoid `-Wformat-signedness` warnings, while making sure
that enums are always cast to a known type when passing them to `printf`
functions, to support compilers and compiler settings where enums are
not default-size signed ints.

- cast integers printed as hex to `unsigned`. (63 times, 20 of them in
  `mbedtls.c`)
- cast misc enums to `int` for printing. (31 times)
- cast `CURL_LOCK_DATA_*` enums to `int`. (4 times)
- cast `CURL_FORMADD_*` enums to `int`. (13 times)
- cast `CURLSHE_*` enums to `int`. (3 times)
- cast `CURLUE_*` enums to `int`. (33 times)
- cast `CURLMSG_*` enums to `int`. (6 times)
- cast `CURLE_*` enums to `int`. (~380 times)
- unit1675: fix mask.
  Follow-up to 7c34365cce #21879

Ref: #18343 (initial attempt)

Closes #20848
2026-06-10 15:14:08 +02:00
Daniel Stenberg
ae2986cdf0
mqtt: return error on truncated Remaining Length
Pointed out by: Zeropath

Closes #21949
2026-06-10 14:40:35 +02:00
Stefan Eissing
f924489b25
ngtcp2: share common functionality
Share common functions/structs between ngtcp2 HTTP/3 and the proxy
version.

Fix bugs in proxy implementation when it comes to stream and pollset
handling and transfer lifetimes.

Curl_multi_xfer_sockbuf_borrow: work without multi

When a connection gets shutdown by a share, the easy handle used is
share->admin and it does not have a multi handle. In that case let
Curl_multi_xfer_sockbuf_borrow() allocate a buffer to be freed on
release.

This happens when a TLS filter sends its last notify through a HTTP/3
proxy tunnel.

Closes #21871
2026-06-10 13:28:05 +02:00
Daniel Stenberg
5c6b488035
digest: flush state on origin or credential change
Verified by test 1686

Closes #21944
2026-06-10 13:20:03 +02:00
A Johnston
084ceb6601
hsts: duplicate live HSTS data in curl_easy_duphandle
Verified by test 1922

Closes #21809
2026-06-09 16:51:47 +02:00
Viktor Szakats
014be82a66
tidy-up: drop redundant == NULL syntax
Where missed by checksrc.

Closes #21935
2026-06-09 14:37:36 +02:00
Viktor Szakats
59213abfb2
tidy-up: drop redundant != NULL syntax
Where missed by checksrc.

Closes #21932
2026-06-09 14:37:36 +02:00
Viktor Szakats
e37417e021
psl: require libpsl 0.16.0 (2016-12-10) or greater
Debian Stretch offers 0.17.0.

Ref: https://github.com/rockdaboot/libpsl/releases/tag/libpsl-0.16.0
Ref: https://sources.debian.org/src/libpsl/

Closes #21933
2026-06-09 14:34:57 +02:00
alhudz
62b118cf22
http-proxy: verify CONNECT response headers
Verifed by test 2107

Closes #21927
2026-06-09 13:56:28 +02:00
Daniel Stenberg
c7cba2fd2d
sigv4: URL encode the user name in the header
- split into sub functions
- add 'aws-sigv4' as keyword for many tests

Verify with test 3222

Reported-by: Trail of Bits
Closes #21923
2026-06-09 13:34:27 +02:00
Viktor Szakats
847aac066d
tidy-up: use uppercase TRUE/FALSE where missing
Keep it only in external API calls and C++ code.

Also:
- curlx/fopen: replace with `!!`.

Spotted by GitHub Code Quality in cf-socket.c.

Closes #21925
2026-06-09 12:52:08 +02:00
Yedaya Katsman
feb609f28b
cf-socket: store errno from do_connect in ctx->error
This fixes a misleading log in verbose mode when ipv6 connectivity isn't
available, presumably also in other cases:

```
* Immediate connect fail for 2a00:1450:4028:806::200e: Network is unreachable
* connect to 2a00:1450:4028:806::200e port 443 from :: port 0 failed: Success
```

Closes #21914
2026-06-09 11:12:14 +02:00
Daniel Stenberg
e66b81a532
cookie: tailmatch the domains for secure override
If a SECURE cookie is set for a sub-domain (`example.com`) and is then
attempted to get set again for more specific part of that domain
(`www.example.com`) without the SECURE property, the second occurance
should not be allowed.

Reported-by: Trail of Bits

Verified by test 3305
Closes #21910
2026-06-09 11:11:07 +02:00
Viktor Szakats
952b04474c
tidy-up: miscellaneous
- badwords: replace stray synonyms with 'null-terminator'.
- tests/FILEFORMAT.md: tidy up feature descriptions.
- printf: replace stray `%i` masks with `%d` for consistency.
- pytest: add comments for empty excepts to try silencing GitHub CodeQL
  warnings.
- tool1394, unit1675: merge nested `if`s.
- dnscache: fix typo in comment.
- fix whitespace, indent and newlines.

Closes #21921
2026-06-09 11:07:55 +02:00
Stefan Eissing
849317ff5c
ws: make pong sending lazy
Do not send PONG frames unless there is sufficient space left in the
websocket send buffer. A server might be lazy in reading our data and
intermediary PONG frames can be skipped by a client (RFC 6455, ch.
5.5.3).

Add test case measuring no real RSS increase on a server blasting with
PING frames.

Closes #21911
2026-06-09 11:05:34 +02:00
Daniel Stenberg
fb9a520873
peer.h: fix typo in comment
Closes #21920
2026-06-09 11:00:01 +02:00
Yedaya Katsman
7b9d74abf6
resolve: Mention in error that IP address is expected
If you try using a DNS name like connect-to supports it can be confusing that
it is illegal. Also make it a bit more readable

Closes #21913
2026-06-09 09:23:52 +02:00
Daniel Stenberg
a2b943b115
digest: escape control codes too
Since the username is decoded when used and control codes are accepted
in HTTP usernames in general, the username encoding for the Digest auth
needs to percent encode such bytes.

Verified by test 3221

Reported-by: Trail of Bits
Closes #21915
2026-06-09 09:20:47 +02:00
Daniel Stenberg
04afd16076
urlapi: URL decode hostname before IP address normalization
With this, IPv6 addresses that end with '%25' with no following zone id are
considered invalid.

Extend test 1560 to verify

Reported-by: Hem Parekh
Closes #21918
2026-06-09 08:42:19 +02:00
alhudz
7de0a7e71a
chunked: reject invalid bytes in trailer
Trailers are delivered to the application as headers via
CLIENTWRITE_TRAILER, but unlike regular response headers they skipped
the verify_header() checks, so a server could smuggle a nul byte (or
stray CR) into a header reaching CURLOPT_HEADERFUNCTION and
curl_easy_header().

Run each assembled trailer line through Curl_verify_header(), the same
validation used for normal headers.

Covered by the new test 2106.

Closes #21896
2026-06-08 13:56:10 +02:00
Stefan Eissing
d69bfad3fa
ssl native_ca_store: always reinit
Add bit `native_ca_store_opt` to keep the setting of
CURLOPT_(PROXY_)SSL_OPTIONS and use that to calculate every easy
transfer if a native CA store shall be used or not.

This avoids `native_ca_store` getting stuck on TRUE after being set
once.

Closes #21902
2026-06-08 13:53:54 +02:00
Stefan Eissing
435fb96dcf
netrc: remember and check filename loaded
Remember the filename of a loaded netrc file to detect changed
configurations in a reused easy handle.

Closes #21903
2026-06-08 13:53:02 +02:00
Viktor Szakats
39d5cead0d
libssh2: save non-standard port to known_hosts
Reported-by: dyingc on github
Fixes #21863

Closes #21874
2026-06-08 13:26:31 +02:00
Daniel Stenberg
5df33efab4
setopt: claer the "custom" CA booleans when set to NULL
Mark them as custom choices only when pointer is passed, and clear them
again when set to NULL.

Closes #21901
2026-06-08 12:37:35 +02:00
Daniel Stenberg
0618ffe50d
Revert "url: remove ssh_config_matches"
This reverts commit 3e9817cd1b.

The change was incorrect as the check was not for the options the commit
message mentions.

Reported-by: ByteRay on hackerone
Closes #21899
2026-06-08 09:09:58 +02:00
Viktor Szakats
7c34365cce
urlapi: fix memleaks on error in parse_hostname_login()
Detected by GitHub Code Quality

Follow-up to acd82c8bfd #11006
Follow-up to 4183b8fe9a #8049

Closes #21879
2026-06-08 00:42:51 +02:00
Stefan Eissing
fbcf10ab84
progress: fx CURLINFO time reporting
Whack the times reported for a transfer (see
https://curl.se/libcurl/c/curl_easy_getinfo.html#TIMES) into order for
all variations of up-/download, http/ftp etc. Make sure they are
reported in the documented order.

There is still the *possibility* of PRETRANSFER being longer then
POSTTRANSFER, if a server sends a response before an upload is done.
POST is the time the first response byte is received, and PRE is the
time the last byte was sent by curl.

This may happen with more likelihood on HTTP/2 and 3 for a server
rejected upload. But for successful uploads, the answer will almost over
come afterwards.

Undo the previous twists in lib500.c tests, adjust pytest timeline
checks.

Fixes #21828
Reported-by: BazaarAcc32 on github
Closes #21843
2026-06-07 14:39:10 +02:00
Daniel Stenberg
317bf7e8a8
ftplistparser: clear strings.target if not symlink
When the struct is passed to the CURLOPT_CHUNK_BGN_FUNCTION callback,
clear the pointer if the provided data is not a symlink.

Closes #21884
2026-06-07 00:26:51 +02:00
Daniel Stenberg
c3c2cfb65d
http: reject spurious CR bytes in headers
Verified by test 2105

Closes #21882
2026-06-06 22:54:25 +02:00
Vasiliy-Kkk
3b9f0972e2 schannel_verify: simplify CryptQueryObject use
- Specify that the content is base64 encoded, rather than rely on
  auto-detect.

- Remove unnecessary sanity check of the returned content type.

Closes https://github.com/curl/curl/pull/21760
2026-06-06 11:27:34 -04:00
Viktor Szakats
d3e9a815c4
tidy-up: miscellaneous
- fix typos.
- badword: add two new words.
- cpp: drop parentheses from standalone `#if` expressions.
- libssh: vertical-align comment block with others.
- clang-format.

Closes #21880
2026-06-05 16:57:38 +02:00