Commit Graph

14303 Commits

Author SHA1 Message Date
Daniel Stenberg
adf2b4fa51
libssh: use CURL_PATH_MAX instead of PATH_MAX
Follow-up to facf59c30e

Reported-by: Viktor Szakats
Bug: https://github.com/curl/curl/pull/15285#issuecomment-2416947731
Closes #15309
2024-10-16 16:27:59 +02:00
Viktor Szakats
7fbcf4b9b7
vquic: fix compiler warning with gcc + MUSL
```
/Users/runner/work/curl-for-win/curl-for-win/curl/lib/vquic/vquic.c: In function 'msghdr_get_udp_gro':
/Users/runner/work/curl-for-win/curl-for-win/curl/lib/vquic/vquic.c:344: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
  344 | #pragma clang diagnostic push
      |
/Users/runner/work/curl-for-win/curl-for-win/curl/lib/vquic/vquic.c:345: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
  345 | #pragma clang diagnostic ignored "-Wsign-compare"
      |
/Users/runner/work/curl-for-win/curl-for-win/curl/lib/vquic/vquic.c:346: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
  346 | #pragma clang diagnostic ignored "-Wcast-align"
      |
/Users/runner/work/curl-for-win/curl-for-win/curl/lib/vquic/vquic.c:350: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
  350 | #pragma clang diagnostic pop
      |
```
https://github.com/curl/curl-for-win/actions/runs/11356281008/job/31587180874#step:3:9534

Follow-up to a571afc02e #14012
Closes #15303
2024-10-16 12:09:02 +02:00
Daniel Stenberg
facf59c30e
libssh2: use the filename buffer when getting the homedir
Avoids having to use a big stack buffer for this.

Closes #15285
2024-10-16 11:55:52 +02:00
Daniel Stenberg
083b4ab6e4
libssh2: put the readdir buffers into struct
... instead of separate malloc() calls:

- removes two mallocs (and associated error handling paths)
- makes cleanup easier

Also reduce maximum SFTP file path lengths to 1024 bytes universally
everywhere. Using the system's own MAX_PATH did not make sense since
this is mostly about getting a remote file name.

Closes #15285
2024-10-16 11:55:47 +02:00
Daniel Stenberg
8403e5a701
tests: fix callback signatures to please UndefinedBehaviorSanitizer
Make test applications use the correct prototypes for callbacks.

Closes #15289
2024-10-15 14:33:47 +02:00
Daniel Stenberg
eed3c8f4b7
curl.h: remove the struct pointer for CURL/CURLSH/CURLM typedefs
It makes the callbacks get different signnatures when used from within
libcurl vs outside of it by libcurl-using applications (such as the
libtests) and this triggers UndefinedBehaviorSanitizer errors.

Closes #15289
2024-10-15 14:33:40 +02:00
Daniel Stenberg
ad1c49bc0e
lib: remove function pointer typecasts for hmac/sha256/md5
Make sure we use functions with the correct prototype.

Closes #15289
2024-10-15 14:32:39 +02:00
Michael Kaufmann
335d325708 conncache: More efficient implementation of cpool_remove_bundle
Closes #15292
2024-10-15 10:45:17 +02:00
Daniel Stenberg
9bee39bfed
url: use same credentials on redirect
Previously it could lose the username and only use the password.

Added test 998 and 999 to verify.

Reported-by: Tobias Bora
Fixes #15262
Closes #15282
2024-10-13 23:18:42 +02:00
Daniel Stenberg
eb77297ccc
lib: move curl_path.[ch] into vssh/
As this contains code only used by SSH backends.

Closes #15284
2024-10-13 23:16:18 +02:00
Stefan Eissing
a7ccd02614
ftp: move listen handling to socket filter
Move the listen/accept handling of the FTP active data connection
into the socket filter and monitor 'connected' status of that as
with passive connections - more or less.

The advantage is that the socket filter now reports being connected
only when the server has actually called and accept() has been done.
This enables to bootstrap the filter chain on the data connection
just like any other. A require SSL filter can then be added right
at the start and does not need to be patched in later.

Still, the active connection keeps on needing special handling in
ftp.c as the control connection needs to be monitored while waiting
as the server might send error responses this way. So, things did
not turn out quite as squeaky clean as hoped for, but still seems
better to do that way.

Closes #14798
2024-10-13 23:15:28 +02:00
Stefan Eissing
3455d360ce
mbedTLS: fix handling of TLSv1.3 sessions
For TLSv1.3, if supported, observer special return code to retrieve
newly arrived session from mbedTLS.

Adjust test expectations now that TLSv1.3 session resumption works in
mbedTLS >= 3.6.0.

Based on #14135 by @ad-chaos
Closes #15245
2024-10-13 23:13:04 +02:00
Stefan Eissing
513904c264
wolfSSL: fix handling of TLSv1.3 sessions
Register a callback to get notified of new SSL sessions by wolfSSL.
Remove the explicit session retrieval after handshake, since this does
not work for TLSv1.3.

Adjust test expectations now that TLSv1.3 session resumption works
in wolfSSL.

Closes #15243
2024-10-13 23:11:39 +02:00
Viktor Szakats
960521d210
smb: do not redefine getpid on Windows
Replace with namespaced local macro `Curl_getpid()`.

Redefining symbols can backfire if that symbol is used in system
headers, especially with unity build. We haven't seen a fallout in CI
or supported envs, but do it anyway for good measure.

Bug report: https://datagirl.xyz/posts/wolfssl_curl_w2k.html
Closes #15263
2024-10-13 18:01:51 +02:00
Stefan Eissing
fe8399f066
gnutls: use session cache for QUIC
Add session reuse for QUIC transfers using GnuTLS. This does not include
support for TLS early data, yet.

Fix check of early data support in common GnuTLS init code to not access
the filter context, as the struct varies between TCP and QUIC
connections.

Closes #15265
2024-10-11 23:37:47 +02:00
Daniel Stenberg
0095f98464
libssh2: split the statemachine function into smaller sub functions
A giant function is hard to read.

Closes #15250
2024-10-11 14:43:16 +02:00
Daniel Stenberg
3b43a05e00
netrc: cache the netrc file in memory
So that on redirects etc it does not reread the file but just parses it
again.

Reported-by: Pierre-Etienne Meunier
Fixes #15248
Closes #15259
2024-10-11 14:40:12 +02:00
Stefan Eissing
962097b8dd
TLS: TLSv1.3 earlydata support for curl
Based on #14135, implement TLSv1.3 earlydata support for the curl
command line, libcurl and its implementation in GnuTLS.

If a known TLS session announces early data support, and the feature is
enabled *and* it is not a "connect-only" transfer, delay the TLS
handshake until the first request is being sent.

- Add --tls-earldata as new boolean command line option for curl.
- Add CURLSSLOPT_EARLYDATA to libcurl to enable use of the feature.
- Add CURLINFO_EARLYDATA_SENT_T to libcurl, reporting the amount of
  bytes sent and accepted/rejected by the server.

Implementation details:
- store the ALPN protocol selected at the SSL session.
- When reusing the session and enabling earlydata, use exactly
  that ALPN protocol for negoptiation with the server. When the
  sessions ALPN does not match the connections ALPN, earlydata
  will not be enabled.
- Check that the server selected the correct ALPN protocol for
  an earlydata connect. If the server does not confirm or reports
  something different, the connect fails.
- HTTP/2: delay sending the initial SETTINGS frames during connect,
  if not connect-only.

Verification:
- add test_02_32 to verify earlydata GET with nghttpx.
- add test_07_70 to verify earlydata PUT with nghttpx.
- add support in 'hx-download', 'hx-upload' clients for the feature

Assisted-by: ad-chaos on github
Closes #15211
2024-10-11 12:28:22 +02:00
Daniel Stenberg
d0377f5a86
multi: convert Curl_follow to static multi_follow
Moved over from transfer.c because it is only used in multi.c

Closes #15260
2024-10-11 12:26:36 +02:00
Daniel Stenberg
be39ed19a5
cookie: overhaul and cleanup
- split the huge Curl_cookie_add() into several smaller static functions

- switch to using the common llist instead of custom linked list

- use less memory for *getlist()

- use bitfields for flags in the Cookie struct

- avoid the copy for date parsing

- more consistent variable naming

Closes #15247
2024-10-11 09:01:03 +02:00
Viktor Szakats
91519bfb74
cmake: use cmake_push_check_state() around feature checks
Enclose
`CMAKE_EXTRA_INCLUDE_FILES`,
`CMAKE_REQUIRED_DEFINITIONS`,
`CMAKE_REQUIRED_FLAGS`,
`CMAKE_REQUIRED_INCLUDES`,
`CMAKE_REQUIRED_LIBRARIES`,
`CMAKE_REQUIRED_LINK_OPTIONS`,
settings within `cmake_push_check_state()`/`cmake_pop_check_state()`
calls. It prevents spilling them into other feature checks. It also
replaces manual resets found in some places (which can have
the undesired side-effect of destroying values meant for global use.)

Cherry-picked from #15157
Closes #15251
2024-10-10 19:35:58 +02:00
Daniel Stenberg
a94973805d
hsts: improve subdomain handling
- on load, only replace existing HSTS entries if there is a full host
  match

- on matching, prefer a full host match and secondary the longest tail
  subdomain match

Closes #15210
2024-10-09 13:48:08 +02:00
Emanuel Komínek
461ce6c616
multi: make curl_multi_cleanup invalidate magic latter
When a multi handle is being cleaned up, it can still cause user
callbacks to be fired. Notably Curl_cpool_destroy calls socket_callback
on all pooled connections. It's still possible for the callback to call
curl_multi_assign leading to an assert.

This commit moves clearing of a multi handle magic to a point where the
multi handle stops being a valid object.

Fixes #15201
Closes #15206
2024-10-09 07:55:21 +02:00
Colton Willey
0f7e72fbcc
wolfssl: use old version API without openssl extra
Closes #15205
2024-10-09 07:53:45 +02:00
Viktor Szakats
e377c91766
GHA: add Linux and macOS mbedTLS jobs, fix issue
- update mbedTLS repo URL.
- switch local mbedTLS build to use CMake, and Ninja.
  CMake build is required to create and install mbedTLS `pkg-config`
  files. (as of v3.6.1)
  `-DCMAKE_POSITION_INDEPENDENT_CODE=ON` required to avoid this error
  when linking mbedtls to `libcurl.so`:
  ```
  /usr/bin/ld: /home/runner/mbedtls/lib/libmbedcrypto.a(cipher.c.o): warning: relocation against `mbedtls_cipher_base_lookup_table' in read-only section `.text'
  /usr/bin/ld: /home/runner/mbedtls/lib/libmbedtls.a(ssl_tls.c.o): relocation R_X86_64_PC32 against symbol `mbedtls_x509_crt_profile_suiteb' can not be used when making a shared object; recompile with -fPIC
  /usr/bin/ld: final link failed: bad value
  ```
  Ref: https://github.com/curl/curl/actions/runs/11245069259/job/31264386723#step:40:43
- make local mbedTLS build 10x smaller by omitting programs and tests.
- GHA/linux: fix cmake warning by adding `-B .` option.
- GHA/linux: add build-only cmake job for packaged mbedTLS (2.x).
- fix compiler warning when building with mbedTLS 2.x:
  ```
  /home/runner/work/curl/curl/lib/vtls/mbedtls.c:344:1: error: ‘mbed_cipher_suite_get_str’ defined but not used [-Werror=unused-function]
    344 | mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size,
        | ^~~~~~~~~~~~~~~~~~~~~~~~~
  ```
  Ref: https://github.com/curl/curl/actions/runs/11244999065/job/31264168295#step:40:50

Also in preparation for #15193
Closes #15208
2024-10-09 02:46:01 +02:00
Daniel Stenberg
e8c024aa99
http_aws_sigv4: avoid local buffer and strcpy
This avoids the buffer, the copy and the previous host name length
limit.

Closes #15200
2024-10-08 16:13:25 +02:00
Daniel Stenberg
c5b8569c7c
tftp: avoid two memcpy/strcpy
Closes #15199
2024-10-08 15:41:42 +02:00
Daniel Stenberg
d90a8f07ed
telnet: avoid two strcpy() by pointing to the strings instead
Closes #15198
2024-10-08 15:40:00 +02:00
Daniel Stenberg
88ef62ba22
setopt: avoid superfluous length checks before strcmp()
Simplify the checks

Closes #15192
2024-10-08 15:37:19 +02:00
Daniel Stenberg
741e07edba
bearssl: avoid strpcy() when generating TLS version log message
Closes #15194
2024-10-08 15:36:05 +02:00
Daniel Stenberg
3dfc256b94
smb: replace use of strcpy() with snprintf()
Closes #15196
2024-10-08 15:34:50 +02:00
Daniel Stenberg
45b7aa6b70
altsvc: avoid using local buffer and memcpy
When parsing alt-svc headers. Store and use the length of the name
separately.

Closes #15191
2024-10-08 12:50:52 +02:00
Daniel Stenberg
60d8663afb
hsts: avoid the local buffer and memcpy on lookup
Closes #15190
2024-10-08 12:49:17 +02:00
Daniel Stenberg
699a2df350
conncache: find bundle again in case it is removed
When the pool is cleaned up due to host limits, the bundle may be
cleaned up as well making the old pointer invalid.

Fixes #15185
Reported-by: Moritz Knüsel
Closes #15186
2024-10-08 11:06:49 +02:00
Daniel Stenberg
40bd652b74
setopt: use a single function for HTTPAUTH and PROXYAUTH
Avoid duplicated almost-the-same code.

Closes #15182
2024-10-08 08:12:45 +02:00
Viktor Szakats
a79f20d376
cmake: do not propagate unused HAVE_GSSAPI_GSSAPI_KRB5_H to C
Closes #15174
2024-10-07 16:14:38 +02:00
Viktor Szakats
e888069f5a
cmake: detect HAVE_NETINET_IN6_H, HAVE_CLOSESOCKET_CAMEL, HAVE_PROTO_BSDSOCKET_H
To sync with `./configure`.

- `HAVE_NETINET_IN6_H` is
  needed by HPE NonStop NSE and NSX systems.
  Follow-up to 76ebd54175 #2155

- `HAVE_CLOSESOCKET_CAMEL`, `HAVE_PROTO_BSDSOCKET_H`
  are for AmigaOS.
  (Note: `./configure` tries to detect these for all targets, cmake does
  it only for AmigaOS, to not inflate configure time.)

Closes #15172
2024-10-07 13:45:20 +02:00
Viktor Szakats
5e70566094
build: detect and use _setmode() with Cygwin/MSYS, also use on Windows
Before this patch `setmode()` was not detected with Cygwin/MSYS, because
it's a macro, not a function, and detection is looking for a function.

Switching to symbol detection doesn't work because it mis-detects it on
BSD systems which features a function with the same name but different
functionality and arguments.

Fix it by looking for a `_setmode()` function on Cygwin/MSYS, and use it
if available.

`_setmode()` is recommended over `setmode()` by Windows documentation so
use that on Windows too. It seems to be available on all supported
compilers, so omit detection.

https://learn.microsoft.com/cpp/c-runtime-library/reference/posix-setmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/setmode

Officially Windows requires argument `_O_BINARY` with an underscore.
`O_BINARY` is also supported but bound to conditions. Continue to use it
for simplicity. Cygwin supports `O_BINARY` (no underscore).

Closes #15169
2024-10-07 12:31:21 +02:00
Daniel Stenberg
e9eda865df
warnless: remove curlx_sktosi and curlx_sitosk
They were only used by test server code. Use plain old typecasts there.

Closes #15153
2024-10-05 00:28:06 +02:00
Daniel Stenberg
6f454bab75
asyn-ares: remove typecast, fix expire
- Use the appropriate variable type for the curlx_tvtoms() return code:
  timediff_t and remove the typecast.

- Simplify the function and avoid the odd expire adjustment that
  probably is a rest from ancient days when the expire function did not
  handle zero millisecond timeouts.

Closes #15145
2024-10-04 14:08:09 +02:00
Daniel Stenberg
566a6d7b09
urlapi: normalize the IPv6 address
As the parsing and address "regeneration" are done anyway, we might as
well use the updated version in the result and thereby A) get a
normalized (and lower cased) version of the address and B) avoid a
strcpy().

Updated test 1560 to verify.

Closes #15143
2024-10-03 16:05:03 +02:00
Stefan Eissing
65eb20260b
openssl quic: populate x509 store before handshake
Since OpenSSL does its own send/recv internally, we may miss the moment
to populate the x509 store right before the server response. Do it
instead before we start the handshake, at the loss of the time to set
this up.

Closes #15137
2024-10-03 14:43:47 +02:00
Stefan Eissing
2400a6c6b2
bufq: unwrite fix
`Curl_bufq_unwrite()` used the head instead of the tail chunk to shrink
the bufq's content. Fix this and add test case that checks correct
behaviour.

Amended test 2601 accordingly.

Reported-by: Chris Stubbs
Closes #15136
2024-10-03 13:27:36 +02:00
Daniel Stenberg
bcec0840b0
lib: use bool/TRUE/FALSE properly
booleans should use the type 'bool' and set the value to TRUE/FALSE

non-booleans should not be 'bool' and should not set the value to
TRUE/FALSE

Closes #15123
2024-10-03 09:31:56 +02:00
Daniel Stenberg
78ed473dbc
wolfssl: add proper colon separator
Follow-up to 6fd5a9777a

Fixes #15132
Reported-by: Viktor Szakats
Closes #15134
2024-10-03 09:28:02 +02:00
Daniel Stenberg
98591551dc
vtls: convert Curl_pin_peer_pubkey to use dynbuf
Closes #15126
2024-10-03 08:33:53 +02:00
Daniel Stenberg
ebd9d67b8a
vtls: convert pubkey_pem_to_der to use dynbuf
... instead of malloc and "manual" buffer stuffing

Closes #15126
2024-10-03 08:33:53 +02:00
Daniel Stenberg
6fd5a9777a
wolfssl: convert malloc + memcpys to dynbuf for cipher string
Closes #15124
2024-10-02 14:43:31 +02:00
Daniel Stenberg
b5d453effa
lib: avoid assigning 'result' temporarily
Closes #15122
2024-10-02 14:38:28 +02:00
Daniel Stenberg
23386872d1
multi: make multi_handle_timeout use the connect timeout
For all states before MSTATE_DO the connect timeout needs to be
considered.

Regression since #13371 (be659030ba) shipped in 8.8.0

Reported-by: Deniz Sökmen
Fixes #15100
Closes #15119
2024-10-02 14:37:21 +02:00