Commit Graph

15572 Commits

Author SHA1 Message Date
Stefan Eissing
dbff3eec45
cf-socket: give information when unable to open socket
Give ERRNO explanation in a failf() when unable to open a socket.
Helps in finding out what the issue preventing your curl to work
really is. Just had a wrong ulimit after a sys update.

Closes #19158
2025-10-20 15:21:47 +02:00
Stefan Eissing
4be9db7bc8
http: accept duplicate location with same value
When a server sends a Location: header repeat with the same location,
ignore the repeats silently.

Follow-up to 9596c4a258
Closes #19159
2025-10-20 14:48:20 +02:00
Viktor Szakats
e7818999db
socks_gssapi: replace gss_release_buffer() with curl free for buffers owned by libcurl
Before this patch, this code used to call `gss_release_buffer()` on
objects with buffers allocated via curl's allocator.
`gss_release_buffer()` calls system (or Win32) free on these buffers,
which may mismatch with curl's allocator. To fix it, align these calls
with the pattern used in vauth modules, by replacing
`gss_release_buffer()` with curl free to release the buffers.

Use `Curl_safefree()` to set the freed pointer to NULL, as
`gss_release_buffer()` did.

Also: use object length var when allocating.

Reported-by: Joshua Rogers

Closes #19018
2025-10-20 14:23:46 +02:00
Daniel Stenberg
1876ed6296
cf-socket: make set_local_ip void, and remove failf()
No callers of this function checked the return code, meaning failures
are not lethal == using failf was wrong, and it can just as well return
void.

Closes #19137
2025-10-20 10:57:48 +02:00
Daniel Stenberg
104299195e
curl_get_line: the final return cannot be reached
Follow-up to 769ccb4d42

Pointed out by CodeSonar
Closes #19154
2025-10-20 10:30:36 +02:00
Daniel Stenberg
9596c4a258
http: return error for a second Location: header
Unless it is identical to the previous one.

Follow-up to dbcaa00657

Adjusted test 580, added test 772 and 773

Fixes #19130
Reported-by: Jakub Stasiak
Closes #19134
2025-10-20 09:35:23 +02:00
Daniel Stenberg
00cb679c04
openssl: remove dead code
A condition in infof_certstack() would always equal true after a
previous change.

Follow-up to e2a4de8a60

Pointed out by Coverity
Closes #19142
2025-10-19 23:48:28 +02:00
Daniel Stenberg
d3b2ba92c7
rustls: exit on error
In init_config_builder_verifier() the call to
rustls_root_cert_store_builder_build() set result on failure but did not
return.

Pointed out by ZeroPath
Closes #19125
2025-10-19 23:47:47 +02:00
Daniel Stenberg
7f19fa9819
lib: add asserts that hostname has content
For all network related protocols there must be a non-blank hostname
used. This change adds a few asserts in some places to make debug/tests
catch mistakes if any such would slip in.

Closes #19146
2025-10-19 23:45:28 +02:00
Yedaya Katsman
55e0526566
openssl: fix unable do typo in failf() calls
Closes #19149
2025-10-19 23:42:54 +02:00
Daniel Stenberg
976333dd40
curl_path: make sure just whitespace is illegal
This function could previously accidentally return true and a NULL path
if only whitespace was provided as argument.

Also, make it stricter and do not allow CR or LF within the string.

Use more strparse parsing.

Drop the comment saying this is from OpenSSH as it has now been
rewritten since then.

Closes #19141
2025-10-19 16:26:01 +02:00
Daniel Stenberg
769ccb4d42
curl_get_line: enhance the API
To make sure callers can properly differentiate between errors and know
cleanly when EOF happens. Updated all users and unit test 3200.

Triggered by a remark by ZeroPath

Closes #19140
2025-10-19 16:25:11 +02:00
Daniel Stenberg
990a23bb97
libssh: return the proper error for readdir problems
The code would return without setting sshc->actualcode or returning the
CURLcode error.

Reported by ZeroPath
Closes #19135
2025-10-19 14:28:55 +02:00
Daniel Stenberg
fffc16dd9c
smtp: return value ignored
Return value from Curl_client_write was overwritten by
smtp_perform_command making errors ignored.

Pointed out by ZeroPath

Closes #19136
2025-10-19 13:17:31 +02:00
Daniel Stenberg
8d302ec936
socks: avoid UAF risk in error path
The code obtained a pointer resp via Curl_bufq_peek(), but called
Curl_bufq_skip() before it would access them in the failf() call.

The Curl_bufq_skip() call can trigger prune_head which may free or
recycle the chunk that resp points into.

Pointed out by ZeroPath
Closes #19139
2025-10-19 13:13:15 +02:00
Jochen Sprickerhof
f03e7c1d64
openldap: fix limit max incoming size test logic
Use LDAP_OPT_SUCCESS for ldap_get_option, as done in the other calls.
ber_sockbuf_ctrl returns 1 on success so reverse the logic.

Follow-up to f91be14bfb
Closes #19138
2025-10-19 13:12:07 +02:00
Daniel Stenberg
6550dd0f3d
wolfssl: clear variable to avoid uninitialized use
Pointed out by ZeroPath
Closes #19126
2025-10-19 11:08:14 +02:00
Tatsuhiro Tsujikawa
e0798466a8
ngtcp2: adopt ngtcp2_conn_get_stream_user_data if available
Adopt ngtcp2_conn_get_stream_user_data which has been available since
ngtcp2 v1.17.0. This improves the time complexity of searching
h3_stream_ctx from O(n) to O(1) where n is the number of stream.

Closes #19132
2025-10-19 11:07:32 +02:00
Joshua Rogers
66e3ff5d0e schannel: fix memory leak
- Do not leak memory on failed setting algorithm cipher list.

Discovered by ZeroPath.


- Do not free backend->cred after failed AcquireCredentialsHandle.

backend->cred is always freed later, during cleanup.


Closes https://github.com/curl/curl/pull/19118
2025-10-19 02:23:36 -04:00
Daniel Stenberg
0217aca9f3
lib: remove newlines from failf() calls
Closes #19124
2025-10-18 23:17:54 +02:00
Joshua Rogers
023e453032
openldap: do not pass newline to infof()
Discovered by ZeroPath
Closes #19120
2025-10-18 22:30:55 +02:00
Joshua Rogers
9021e42c02
ldap: do not pass a \n to failf()
Discovered by ZeroPath
Closes #19122
2025-10-18 22:16:33 +02:00
Joshua Rogers
bff9679a01
schannel_verify: do not call infof with an appended \n
Discovered by ZeroPath
Closes #19123
2025-10-18 22:15:26 +02:00
Daniel Stenberg
8de898414c
openssl: free UI_METHOD on exit path
In providercheck(), when failing to open the "store", the exit path
would not previously free the created UI_METHOD and instead leak this
resource.

Pointed out by ZeroPath

Closes #19114
2025-10-18 12:54:19 +02:00
Viktor Szakats
f32451c12b
curlx: promote Curl_fseeko() to curlx_fseek(), use it in src
- tool_formparse: replace truncated `fseek` with `curlx_fseek`.
- tool_operate: replace truncated `fseek` with `curlx_fseek`.
- tool_paramhlp: replace local duplicate `myfseek`, with `curlx_fseek`.

Follow-up to 4fb12f2891 #19100

Closes #19107
2025-10-18 02:25:10 +02:00
Daniel Stenberg
b9b8a7a5df
openssl: fix resource leak in provider error path
Pointed out by ZeroPath

Closes #19111
2025-10-18 00:40:13 +02:00
Daniel Stenberg
c921f6d052
wolfssl: fix resource leak in verify_pinned error paths
Pointed out by ZeroPath

Closes #19110
2025-10-17 23:34:04 +02:00
Daniel Stenberg
e29706d6e2
mbedtls: move the crypto init into the vtls init function
Follow-up to 3a305831d1

Closes #19108
2025-10-17 23:33:12 +02:00
Viktor Szakats
87b72b8182
krb5: fix output_token allocators in the GSS debug stub (Windows)
Before this patch system `malloc()`/`free()` were used to allocate
the buffer returned in the `output_token` object from the debug stub
of `gss_init_sec_context()` when enabled via `CURL_STUB_GSS_CREDS` in
debug-enabled libcurl builds. This object is later released via stock
`gss_release_buffer()`, which, in the Windows builds of MIT Kerberos,
doesn't use the system `free()`, but the Win32 `HeapFree()`.

Fix it by using the GSS alloc/free macros: `gssalloc_malloc()` and
`gssalloc_free()` from `gssapi_alloc.h`.

To make this work without MIT Kerberos feature detection, use a canary
macro to detect a version which installs `gssapi_alloc.h` for Windows.
For <1.15 (2016-11-30) releases, that do not install it, disable the GSS
debug stub in libcurl.

Strictly speaking, non-Windows builds would also need to use GSS
allocators, but, detecting support for `gssapi_alloc.h` is impossible
without build-level logic. Built-level logic is complex and overkill,
and MIT Kerberos, as of 1.22.1, uses standard malloc/free on
non-Windows platforms anyway. (except in GSS debug builds.)

Follow-up to 73840836a5 #17752

Closes #19064
2025-10-17 17:47:22 +02:00
Daniel Stenberg
25eb34dd3e
KNOWN_BUGS: SOCKS-SSPI discards the security context
Also make the verbose log say it

Pointed out by ZeroPath

Closes #19103
2025-10-17 17:45:06 +02:00
Daniel Stenberg
e9455ea523
rustls: make read_file_into not reject good files
For files with sizes using an exact multiple of 256 bytes, the final
successful read(s) filled the buffer(s) and the subsequent fread
returned 0 for EOF, which caused read_file_into to fail.

Now, it needs to return 0 and not be EOF to be an error.

Follow-up to dd95a49d49

Pointed out by ZeroPath
Closes #19104
2025-10-17 17:44:14 +02:00
Stefan Eissing
5cefb455d4
quic: improve UDP GRO receives
Closes #19101
2025-10-17 17:23:46 +02:00
Stefan Eissing
1d01d4975f
socks_sspi: use the correct free function
When freeing buffers allocated by SSPI, use its own function, not free().

Reported-by: Joshua Rogers
Closes #19046
2025-10-17 16:59:11 +02:00
Viktor Szakats
14e4d9c3c7
setopt: fix unused variable warning in minimal build
Found via: #17961

Closes #19102
2025-10-17 16:19:42 +02:00
Daniel Stenberg
4fb12f2891
mime: fix use of fseek()
Avoid the possible 64-bit offset truncation when used on systems with
small 'long', like Windows.

bonus: make mime_open_file() return bool

Pointed out by ZeroPath
Closes #19100
2025-10-17 16:13:35 +02:00
Daniel Stenberg
c0564ceb3a
cf-socket: if FD_CLOEXEC fails on accepted socket, cleanup
Follow-up to 9d7b532404

Pointed out by ZeroPath

Closes #19098
2025-10-17 16:12:34 +02:00
Daniel Stenberg
fbff1d5b90
openssl: avoid overwriting 'result' after error
Follow-up to eefd03c572

Pointed out by ZeroPath https://zeropath.com/
Closes #19099
2025-10-17 15:48:47 +02:00
Daniel Stenberg
3df71e6dc2
openssl: fail if more than MAX_ALLOWED_CERT_AMOUNT certs
Detect and prevent abuse or mistakes. Limit set to 100.

Closes #19091
2025-10-17 13:36:57 +02:00
Stefan Eissing
f221cdeabe
ngtcp2: add a comment explaining write result handling
The choice to continue processing incoming data although the
writeout of the headers/data failed is not obvious. Add a comment
explaining why this is done.

Closes #19093
2025-10-17 13:36:21 +02:00
Daniel Stenberg
e2a4de8a60
openssl: better return code checks when logging cert data
Pointed out by ZeroPath

Closes #19094
2025-10-17 12:41:04 +02:00
Daniel Stenberg
c4db9eb491
rustls: limit snprintf proper in cr_keylog_log_cb()
It should limit the size to the size of the target array, not the
incoming data.

Pointed out by ZeroPath
Closes #19095
2025-10-17 12:38:36 +02:00
Viktor Szakats
3a305831d1
mbedtls: add support for 4.0.0
After this patch libcurl requires (as already documented)
the `curl_global_init()` call when using the `curl_formadd()` API with
mbedTLS.

Note: NTLM is not supported with mbedTLS 4+, because it lacks
the necessary crypto primitive: DES.

Also:
- lib: de-dupe mbedTLS minimum version checks into `curl_setup.h`.
- lib: initialize PSA Crypto as part of `curl_global_init()`.
  For MD5, SHA-256, `curl_formadd()`, and MultiSSL builds with mbedTLS
  but where mbedTLS isn't the default backend.
- lib1308: fix to call `curl_global_init()` (for the Form API).
- curl_ntlm_core: disable with mbedTLS 4+.
- md4: disable mbedTLS implementation when building against 4.x.
- md5: use mbedTLS PSA Crypto API when available, otherwise use
  the default local implementation.
- sha256: use mbedTLS PSA Crypto API when available, otherwise use
  the default local implementation.
- vtls/mbedtls: drop PSA Crypto initialization in favor of
  `curl_global_init()`.
- vtls/mbedtls: use PSA Crypto random API with all mbedTLS versions.
- vtls/mbedtls: do the same for the SHA-256 callback.
- autotools: detect mbedTLS 4+, and disable NTLM for 3.x.
- cmake: disable NTLM for mbedTLS 3.x.
- GHA/linux: keep building mbedTLS 3.x manually and use it in
  an existing job, while also enabling pytest in it.
- GHA/linux: bump to mbedTLS 4.0.0.
  Closes #19075
  Closes #19074

Refs:
https://github.com/Mbed-TLS/mbedtls/releases/tag/mbedtls-4.0.0
https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-4.0.0/docs/4.0-migration-guide.md
https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-4.0.0/tf-psa-crypto/docs/1.0-migration-guide.md [404]
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/1.0-migration-guide.md
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/psa-transition.md
627f727bbe/docs/4.0-migration-guide

Closes #19077
2025-10-17 11:50:48 +02:00
Daniel Stenberg
7e12139719
imap: treat capabilities case insensitively
Reported-by: Joshua Rogers
Fixes #19089
Closes #19090
2025-10-17 10:40:37 +02:00
Daniel Stenberg
f91be14bfb
openldap: limit max incoming size
Set the maximum allowed size of an incoming LDAP message, which to
OpenLDAP means that it allows malloc() up to this size. If not set,
there is no limit and we instead risk a malloc() failure.

The limit is arbitrarily set to 256K as I can't figure out what a
reasonable value should be.

OpenLDAP docs: https://openldap.org/software/man.cgi?query=lber-sockbuf&apropos=0&sektion=0&manpath=OpenLDAP+2.6-Release&arch=default&format=html

Bug: https://issues.oss-fuzz.com/issues/432441303
Closes #19087
2025-10-16 22:23:37 +02:00
Viktor Szakats
1a81a8e478
version: add GSS backend name and version
MIT Kerberos version detection is implemented for autotools and cmake.

Examples:
```
curl 8.17.0-DEV (x86_64-pc-linux-gnu) ... mbedTLS/3.6.4 libidn2/2.3.7 nghttp2/1.59.0 libgss/1.0.4 OpenLDAP/2.6.7
curl 8.17.0-DEV (x86_64-pc-linux-gnu) ... LibreSSL/4.1.1 libidn2/2.3.7 nghttp2/1.59.0 mit-krb5/1.20.1 OpenLDAP/2.6.7
curl 8.17.0-DEV (x86_64-pc-linux-gnu) ... LibreSSL/4.1.1 libidn2/2.3.7 nghttp2/1.59.0 mit-krb5 OpenLDAP/2.6.7
curl 8.17.0-DEV (x86_64-pc-linux-gnu) ... LibreSSL/4.1.1 nghttp2/1.59.0 mit-krb5/1.20.1 OpenLDAP/2.6.7
curl 8.17.0-DEV (aarch64e-apple-darwin24.6.0) ... GnuTLS/3.8.10 libidn2/2.3.8 libssh2/1.11.1 nghttp2/1.67.1 mit-krb5/1.22.1
```

Also:
- cmake/FindGSS: strip project name ("Kerberos 5 release") from
  the version string when detected via `krb5-config`.

Closes #19073
2025-10-16 16:19:05 +02:00
Stefan Eissing
c37ed9a11e
apple sectrust: add to features
It should be visible in the feature list that libcurl is build with
Apple SecTrust enabled.

Closes #19057
2025-10-16 10:58:45 +02:00
Daniel Stenberg
71d5525113
connect: remove redundant condition in shutdown start
Pointed out by CodeSonar

Closes #19079
2025-10-16 08:56:16 +02:00
Daniel Stenberg
f8cd64e3ab
urldata: make redirect counter 16 bit
Instead of long (up to 64-bit) as the maximum allowed value set since
b059f7deaf is 0x7fff. Saves 2 or 6 bytes.

Closes #19072
2025-10-15 12:34:33 +02:00
Daniel Stenberg
b7f2355b8b
urldata: make 'retrycount' a single byte
Since it only counts up to 5

Closes #19071
2025-10-15 12:33:03 +02:00
Daniel Stenberg
62961d6cc5
lib: stop NULL-checking conn->passwd and ->user
They always point to a string. The string might be zero length.

Closes #19059
2025-10-15 10:44:51 +02:00