Commit Graph

15400 Commits

Author SHA1 Message Date
Viktor Szakats
20142f5d06
build: avoid overriding system symbols for fopen functions
By introducing wrappers for them in the curlx namespace:
`curlx_fopen()`, `curlx_fdopen()`, `curlx_fclose()`.

The undefine/redefine/`(function)()` methods broke on systems
implementing these functions as macros. E.g. AIX 32-bit's `fopen()`.

Also:
- rename `lib/fopen.*` to `lib/curl_fopen.*` (for `Curl_fopen()`)
  to make room for the newly added `curlx/fopen.h`.
- curlx: move file-related functions from `multibyte.c` to `fopen.c`.
- tests/server: stop using the curl-specific `fopen()` implementation
  on Windows. Unicode isn't used by runtests, and it isn't critical to
  run tests on longs path. It can be re-enabled if this becomes
  necessary, or if the wrapper receives a feature that's critical for
  test servers.

Reported-by: Andrew Kirillov
Bug: https://github.com/curl/curl/issues/18510#issuecomment-3274393640

Follow-up to bf7375ecc5 #18503
Follow-up to 9863599d69 #18502
Follow-up to 3bb5e58c10 #17827

Closes #18634
2025-09-30 01:10:36 +02:00
Viktor Szakats
e17aa98bfe
cmake: use more COMPILER_OPTIONS, LINK_OPTIONS / LINK_FLAGS
- replace `COMPILE_FLAGS` with `COMPILE_OPTIONS` that superceded it.

  Follow-up to 6140dfcf3e
  https://cmake.org/cmake/help/v4.1/prop_sf/COMPILE_FLAGS.html

- replace `target_link_libraries()` with `LINK_FLAGS` property for
  CMake <=3.12, because we are passing linker options (not libs).

  Follow-up to 91720b620e #18468
  Follow-up to 548873921c #17670
  Follow-up to 95aea798db #5843
  https://cmake.org/cmake/help/v3.7/command/target_link_libraries.html
  https://cmake.org/cmake/help/v3.7/prop_tgt/LINK_FLAGS.html

- replace `target_link_options()` with `LINK_OPTIONS` propery for
  CMake 3.13+, to use the modern style.

  Follow-up to 91720b620e #18468
  Follow-up to 548873921c #17670
  https://cmake.org/cmake/help/v3.13/command/target_link_options.html
  https://cmake.org/cmake/help/v3.13/prop_tgt/LINK_OPTIONS.html

Also:

- fix to append to, not override, previously set linker options when
  using `CURL_LIBCURL_VERSIONED_SYMBOLS=ON`. Before this patch, it was
  overwriting linker options when using `CURL_CODE_COVERAGE=ON`.

  Follow-up to 91720b620e #18468

Closes #18762
2025-09-29 13:07:14 +02:00
Viktor Szakats
95e50ad694
tidy-up: miscellaneous
- GHA/checkdocs: rename `spellcheck` job to `pyspelling` to say
  the exact tool used.
- GHA/checkdocs: restore a comment.
- GHA/linux: add `-B .` to a cmake configure to avoid warning, and
  future breakage.
- autotools: use correct casing for `Schannel`.
- doh: update RFC URL.
- drop redundant parenthesis.
- fix indentation, whitespace.

Closes #18756
2025-09-27 12:59:07 +02:00
Daniel Stenberg
b5ffe30e5b
cf-ip-happy: mention unix domain path, not port number
In the connect error message if a unix domain socket was used.

Reported-by: kuchara on github
Ref: #18748
Closes #18749
2025-09-26 17:29:12 +02:00
Daniel Stenberg
72f72f678d
openldap: check ber_sockbuf_add_io() return code
The man page says nothing about what the return code means but Howard
Chu tells me it is 0 on success, -1 on fail.

Help-by: Howard Chu

Closes #18747
2025-09-26 14:29:49 +02:00
Stefan Eissing
061e265502
http: handle user-defined connection headers
When there is more than one user-supplied 'Connection: ' header, add
values that curl needs internally to the first one and emit all
subsequent ones thereafter.

Fixes #18662
Reported-by: Evgeny Grin (Karlson2k)
Closes #18686
2025-09-26 09:27:50 +02:00
Daniel Stenberg
16e0a2098d
openssl: fail the transfer if ossl_certchain() fails
Since it would indicate errors to the degree that continuing would just
risk hiding the earlier errors or make things weird.

Inspired by a report in Joshua's sarif data

Closes #18646
2025-09-25 22:25:20 +02:00
Daniel Stenberg
b8f10be4f2
libssh: acknowledge SSH_AGAIN in the SFTP state machine
Reported in Joshua's sarif data

Closes #18740
2025-09-25 17:26:47 +02:00
Daniel Stenberg
9595921b06
libssh: clarify myssh_block2waitfor
Fixed misleading comment. Simplified the bit setup.

Reported in Joshua's sarif data

Closes #18739
2025-09-25 17:26:01 +02:00
Stefan Eissing
f5bae285f3
socks: handle error in verbose trace gracefully
Adjust the flow to always succeed in verbose trace of connect.

Reported in Joshua's sarif data

Closes #18722
2025-09-25 16:55:22 +02:00
Daniel Stenberg
9f75603d4f
tftp: only check address if it was stored
If recvfrom() fails, it might not have stored an address.

Follow-up to c4f9977c66

Pointed out by CodeSonar

Closes #18738
2025-09-25 16:54:19 +02:00
Daniel Stenberg
bebc8df0f7
schannel_verify: use more human friendly error messages
Closes #18737
2025-09-25 16:53:29 +02:00
Stefan Eissing
442943fb8e
openssl: set io_need always
When OpenSSL reports SSL_ERROR_WANT_READ, set the io_need explicitly.
It should have already been set by the BIO, but be safe.

Reported in Joshua's sarif data

Closes #18733
2025-09-25 14:19:50 +02:00
Stefan Eissing
221b7dda38
transfer: avoid busy loop with tiny speed limit
When a transfer has a speed limit less than 4, the receive loop early
exits without receiving anything, causing a busy loop for that transfer.

Perform that check only after the first receive has been done.

Reported in Joshua's sarif data

Closes #18732
2025-09-25 14:18:35 +02:00
Stefan Eissing
771dd9d9e7
quiche: when ingress processing fails, return that error code
Instead of a general CURLE_RECV_ERROR.

Reported in Joshua's sarif data

Closes #18730
2025-09-25 14:17:39 +02:00
Stefan Eissing
dec661c81c
wolfssl: fix error check in shutdown
When trying to send the TLS shutdown, use the return code
to check for the cause.

Reported in Joshua's sarif data

Closes #18729
2025-09-25 14:16:56 +02:00
Stefan Eissing
15b4b96188
rustls: fix comment describing cr_recv()
The comments on `cf_recv()` function were outdated and described
calling conventions that no longer are true.

Reported in Joshua's sarif data

Closes #18728
2025-09-25 14:14:02 +02:00
Stefan Eissing
e02cbe94ff
mbedtls: check result of setting ALPN
The result of setting the negotiated ALPN was not checked, leading
to reporting success when it should not have.

Reported in Joshua's sarif data

Closes #18727
2025-09-25 14:13:09 +02:00
Stefan Eissing
36eb26381c
quiche: fix verbose message when ip quadruple cannot be obtained.
Reported in Joshua's sarif data

Closes #18726
2025-09-25 14:12:11 +02:00
Stefan Eissing
ee2dd2d6cb
openssl-quic: handle error in SSL_get_stream_read_error_code
The return code of SSL_get_stream_read_error_code() was not checked
in one location, but others. Make that consistent.

Reported in Joshua's sarif data

Closes #18725
2025-09-25 14:11:25 +02:00
Stefan Eissing
887b863b00
openssl: clear retry flag on x509 error
When loading the trust anchors and encountering an error, clear
a possibly set retry flag.

Reported in Joshua's sarif data

Closes #18724
2025-09-25 14:10:00 +02:00
Stefan Eissing
5f4f70e06d
ngtcp2: fix early return
On a failed tls handshake, the receive function returned without
restoring the current data.

Reported in Joshua's sarif data

Closes #18723
2025-09-25 14:09:15 +02:00
Stefan Eissing
b0f6593219
openssl-quic: check results better
Fail on errors from SSL_handle_events().
Force quit Caddy test instance that is left hanging longer with
openssl-quic tests for unknown reasons.

Reported in Joshua's sarif data

Closes #18720
2025-09-25 14:07:56 +02:00
Stefan Eissing
9e8b05fb99
wolfssl: check BIO read parameters
Check parameters passed more thoroughly and assure that current 'data'
also exists.

Reported in Joshua's sarif data

Closes #18718
2025-09-25 14:05:50 +02:00
Stefan Eissing
cbc30d4ed2
vtls: alpn setting, check proto parameter
When setting the negotiated alpn protocol, either then length
must be 0 or a pointer must be passed.

Reported in Joshua's sarif data

Closes #18717
2025-09-25 14:04:14 +02:00
Stefan Eissing
ccd2b03b0d
socks: rewwork, cleaning up socks state handling
Restructured the code in the following ways:

* add terminal states SUCCESS and FAILED
* split SOCK4 and SOCK5 states to be more clear
* use `bufq` for send/recv of SOCK messages
* reduce SOCKS4 states, more speaking names
* for most states, move code into static function
* reduce SOCKS5 states, more speaking names
* add helpers for traversing to FAILED state
* add helper to flush bufq
* add hepler to read minimum amount into bufq

Closes #18401
2025-09-25 14:03:10 +02:00
Stefan Eissing
b3fc692568
lib: upgrade/multiplex handling
Improvements around HTTP Upgrade: and multiplex hanndling:

* add `Curl_conn_set_multiplex()` to set connection's multiplex
  bit and trigger "connchanged" events
* call `Curl_conn_set_multiplex()` in filters' `CF_CTRL_CONN_INFO_UPDATE`
  implementation where other connection properties are updated.
  This prevents connection updates before the final filter chain
  is chosen.
* rename enum `UPGR101_INIT` to `UPGR101_NONE`
* rename connection bit `asks_multiplex` to `upgrade_in_progress`
* trigger "connchanged" when `upgrade_in_progress` clears
* rename `WebSockets` to `WebSocket` as it is the common term
  used in documentation

Closes #18227
2025-09-25 14:00:37 +02:00
Daniel Stenberg
943166fed3
socks_sspi: bail out on too long fields
A probably unnecessary precaution but since the field sizes are 16 bit in the
protocol this makes sure to fail if they would ever be larger as that would go
wrong.

Reported in Joshua's sarif data

Closes #18719
2025-09-25 13:35:25 +02:00
Daniel Stenberg
20d1c6e92e
socks_gssapi: remove superfluous releases of the gss_recv_token
Reported in Joshua's sarif data

Closes #18714
2025-09-25 11:23:04 +02:00
Stefan Eissing
c9fce97dcb
cf-h2-proxy: break loop on edge case
nghttp2 always consumes the memory, but be safe in case it ever decideds
to not to.

Fixes J2
Reported in Joshua's sarif data
Closes #18715
2025-09-25 11:22:24 +02:00
Daniel Stenberg
98dae1d992
socks_gssapi: remove the forced "no protection"
If a protected connection is requested, don't claim to drop down to "no
protection".

Reported in Joshua's sarif data

Closes #18712
2025-09-25 10:11:28 +02:00
Daniel Stenberg
aaa39873ea
socks_gssapi: make the gss_context a local variable
Reported-by: Stanislav Fort
Closes #18711
2025-09-25 09:08:08 +02:00
Daniel Stenberg
0f1657ca75
mbedtls: handle WANT_WRITE from mbedtls_ssl_read()
The mbedtls_ssl_read() function is documented to be able to also return
MBEDTLS_ERR_SSL_WANT_WRITE, so act on that accordingly instead of
returning error for it.

Assisted-by: Stefan Eissing

Reported in Joshua's sarif data
Closes #18682
2025-09-25 09:07:09 +02:00
Daniel Stenberg
b011e3fcfb
vssh: drop support for wolfSSH
The implementation was incomplete and lesser than the other backends. No
one ever reported a bug or requested enhancements for this, indicating
that this backend was never used.

Closes #18700
2025-09-24 22:59:33 +02:00
Daniel Stenberg
470611d76c
hostip: remove unnecessary leftover INT_MAX check in Curl_dnscache_prune
The math already uses timediff_t so no need for the extra logic

Ref: #18678
Closes #18680
2025-09-24 14:11:36 +02:00
Daniel Stenberg
66c7e92ae4
Revert "cf_socket_recv: don't count reading zero bytes as first byte"
This reverts commit df60e8fe70.

The "first byte" checkpoint is not strictly the first byte received, but
the sign of first traffic from the server, which a closed connection
also is.

Closes #18676
2025-09-24 14:09:05 +02:00
Daniel Stenberg
7cb5e39f36
socks_gssapi: reject too long tokens
If GSS returns a token to use that is longer than 65535 bytes, it can't
be transmitted since the length field is an unisgned 16 bit field and
thus needs to trigger an error.

Reported in Joshua's sarif data

Closes #18681
2025-09-24 14:07:03 +02:00
Stefan Eissing
976a08985a
ares: fix leak in tracing
When DNS tracing is enabled, a string allocated by ares was not freed.

Reported-by: jmaggard10 on github
Bug: https://github.com/curl/curl/pull/18251#pullrequestreview-3255785083
Closes #18691
2025-09-24 14:06:24 +02:00
Viktor Szakats
cd20f7b653
libssh: drop two unused assigments
Reported in macOS clang-tidy v21.1.1 build, after enabling libssh in it:
```
lib/vssh/libssh.c
lib/vssh/libssh.c:1342:9: error: Value stored to 'to_t' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
 1342 |         to_t = STRE_OK;
      |         ^
lib/vssh/libssh.c:1342:9: note: Value stored to 'to_t' is never read
lib/vssh/libssh.c:1349:9: error: Value stored to 'from_t' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
 1349 |         from_t = STRE_OK;
      |         ^
lib/vssh/libssh.c:1349:9: note: Value stored to 'from_t' is never read
2 warnings generated.
```
Ref: https://github.com/curl/curl/actions/runs/17909917954/job/50918955923?pr=18660#step:11:182

Cherry-picked from #18660
Closes #18684
2025-09-22 13:02:10 +02:00
Viktor Szakats
aa9fa4d68e
rustls: fix clang-tidy warning
Seen with v21.1.1, non-debug-enabled build:
```
lib/vtls/rustls.c:415:23: error: File position of the stream might be 'indeterminate'
after a failed operation. Can cause undefined behavior [clang-analyzer-unix.Stream,-warnings-as-errors]
  415 |     const size_t rr = fread(buf, 1, sizeof(buf), f);
      |                       ^
```
Ref: https://github.com/curl/curl/actions/runs/17898248031/job/50887746633?pr=18660#step:11:174

Cherry-picked from #18660
Closes #18670
2025-09-22 10:11:31 +02:00
Daniel Stenberg
c4f9977c66
tftp: pin the first used address
Store the used remote address on the first receive call and then make
sure that it remains the same address on subsequent calls to reduce the
risk of tampering. Doesn't make the transfer secure because it is still
unauthenticated and clear text.

Reported in Joshua's sarif data

Closes #18658
2025-09-21 23:01:01 +02:00
Daniel Stenberg
a72e1552f2
telnet: refuse IAC codes in content
Ban the use of IAC (0xff) in telnet options set by the application. They
need to be escaped when sent but I can't see any valid reason for an
application to send them.

Of course, an application sending such data basically ask for trouble.

Reported in Joshua's sarif data

Closes #18657
2025-09-21 23:00:02 +02:00
Viktor Szakats
e5d9c871f0
tidy-up: assortment of small fixes
- examples/headerapi: fix wrong cast.
- curl_ngtcp2: delete stray character from error message.
- rustls: fix inline variable declaration.
- sendf: drop redundant `int` cast.
- libtest/cli_ws_data: drop cast with mismatched signedness.

Cherry-picked from #18343

Closes #18664
2025-09-21 16:50:14 +02:00
Daniel Stenberg
d57e7cf20d
ws: reject curl_ws_recv called with NULL buffer with a buflen
Arguably this is just a bad application.

Reported in Joshua's sarif data

Closes #18656
2025-09-21 11:15:19 +02:00
Daniel Stenberg
0c53a5e5dc
openldap: check ldap_get_option() return codes
Do not just assume that they always work.

Reported in Joshua's sarif data

Closes #18653
2025-09-21 09:50:23 +02:00
Daniel Stenberg
ab3a293fd0
libssh: fix range parsing error handling mistake
The range-parsing returned CURLE_RANGE_ERROR directly on one error
instead of calling myssh_to_ERROR() like it should and like it does for
all other errors.

Reported in Joshua's sarif data

Closes #18652
2025-09-21 09:49:38 +02:00
Daniel Stenberg
05930f304b
rustls: use %zu for size_t in failf() format string
Reported in Joshua's sarif data

Closes #18651
2025-09-21 09:48:47 +02:00
Daniel Stenberg
a9baf82a9b
ftp: fix ftp_do_more returning with *completep unset
Specifically, when ftpc->wait_data_conn was true and
Curl_conn_connect(...) returned with serv_conned == false the code
called ftp_check_ctrl_on_data_wait and returned without setting
*completep.

Now set it to 0 at function start to avoid this happening again.

Reported in Joshua's sarif data

Closes #18650
2025-09-21 09:47:01 +02:00
Daniel Stenberg
3b22ed999e
telnet: return error on crazy TTYPE or XDISPLOC lengths
Also use the packet size msnprintf() stores instead of calculating it
separately.

Reported in Joshua's sarif data

Closes #18648
2025-09-21 09:45:29 +02:00
Daniel Stenberg
3d8e15650c
vtls_int.h: clarify data_pending
Suggested-by: Joseph Birr-Pixton

Closes #18644
2025-09-21 09:43:28 +02:00