Commit graph

15699 commits

Author SHA1 Message Date
Viktor Szakats
ae7b4eeade
curl_setup.h: drop stray #undef stat (Windows)
Follow-up to 9678ff5b1b #18776

Closes #19519
2025-11-14 01:47:12 +01:00
Daniel Stenberg
0afb52a0cd
code: minor indent fixes before closing braces
Closes #19512
2025-11-13 17:27:40 +01:00
Daniel Stenberg
833c429627
wolfssl: simplify wssl_send_earlydata
Move out logic from a switch() expression and return error directly
instead of using goto. This also removes the odd-looking two subsequent
closing braces at the same indent level.

Closes #19509
2025-11-13 13:46:28 +01:00
Stefan Eissing
cb2bcb681f
lib: eliminate size_t casts
Add new functions in `curlx/warnless.h` for controlled type
conversions:

* curlx_uitouz, convert unsigned into to size_t (should always work)
* curlx_uztoso, convert size_t to curl_off_t, capping at CURL_OFF_T_MAX
* curlx_sztouz, convert ssize_t to size_t, return TRUE when ok
* curlx_sotouz_range, convert curl_off_t to size_t interval, capping
  values to interval bounds

Remove some unnecesary casts, convert some internal recv functions
to the "return result, have size_t* arg" pattern.

Closes #19495
2025-11-13 13:32:19 +01:00
Stefan Eissing
78a610cb83
lib: rename curlx_timediff to curlx_timeleft_ms
Rename `Curl_timeleft()` to `Curl_timeleft_ms()` to make the units in
the returned `timediff_t` clear. (We used to always have ms there, but
with QUIC started to sometimes calc ns as well).

Rename some assigned vars without `_ms` suffix for clarity as well.

Closes #19486
2025-11-13 13:12:58 +01:00
Daniel Stenberg
3f0629ca44
cookie: propagate errors better, cleanup the internal API
Overhaul of the internal cookie APIs and an attempt to better return
errors for OOM and similar critical problems, separate from ordinary and
benign parsing problems.

Closes #19493
2025-11-13 10:07:24 +01:00
Daniel Stenberg
296ffc45c3
schannel: replace atoi() with curlx_str_number()
The last atoi() call removed from libcurl

Closes #19483
2025-11-13 09:06:02 +01:00
Daniel Stenberg
a862920246
hostip: don't store negative lookup on OOM
When convert_ipaddr_direct() returns error due to OOM, it must not be
stored as a negative cache result.

Closes #19484
2025-11-12 12:19:12 +01:00
Daniel Stenberg
b2e0b4d008
libssh2: replace atoi() in ssh_force_knownhost_key_type
Closes #19479
2025-11-12 11:18:26 +01:00
Daniel Stenberg
7428060b0e
libssh2: cleanup ssh_force_knownhost_key_type
- Use arrays instead pointers
- Narrow variable scopes

Closes #19479
2025-11-12 11:18:18 +01:00
Daniel Stenberg
7aaf9a3152
http: replace atoi use in Curl_http_follow with curlx_str_number
In an attempt to weed out atoi() use all over.

Closes #19478
2025-11-12 10:44:49 +01:00
Daniel Stenberg
3b4bf3fcfa
telnet: replace atoi for BINARY handling with curlx_str_number
Also, only consider 0 to be a valid switch-off. Previously any value
except 1 had the same effect.

Closes #19477
2025-11-12 10:41:52 +01:00
Daniel Stenberg
97b0abb46b
noproxy: replace atoi with curlx_str_number
To better reject junk and detect overflows. There were already
additional precautions and protections in place, but this is cleaner.

Extended the 1614 unit tests with some more bad syntax cases.

Closes #19475
2025-11-12 10:30:59 +01:00
Viktor Szakats
4841e4290d
badwords: re-sync with curl-www, fix issues found
Also:
- replace `manpage` with `man page`, add to `badwords.txt`.
- badwords.pl: import `-w` feature from curl-www, syncing the two
  scripts fully.
- badwords.txt: import missing items from curl-www, syncing the two
  files fully.
- pyspelling.words: drop `cURL` allowed word.

Closes #19468
2025-11-12 00:53:44 +01:00
Daniel Stenberg
f1f5cc781c
cf-socket: split out the MTU and GRO setopts into sep functions
It simplifies the #ifdefs and declaring of local variables slightly.

Closes #19467
2025-11-11 17:57:40 +01:00
Daniel Stenberg
3d9f7b436c
noproxy: simplify Curl_check_noproxy
By creating two separate matching functions for name and IP.

Closes #19466
2025-11-11 16:43:41 +01:00
Daniel Stenberg
6ca1d05797
ftp: remove #ifdef for define that is always defined
The CURL_FTP_HTTPSTYLE_HEAD logic was added back in 2007 with the
intention to remove that logic one day, but since we never bump the
SONAME it is not likely to happen anytime soon. Remove again for
readability.

Follow-up to 3217809294

Closes #19463
2025-11-11 16:27:19 +01:00
Daniel Stenberg
5bd670c393
wolfssl: avoid NULL dereference in OOM situation
Verify that wolfSSL_BIO_meth_new() actually works and handle situations
where it returns NULL.

Reported-by: Stanislav Fort (Aisle Research)
Closes #19459
2025-11-11 16:23:27 +01:00
Daniel Stenberg
28380bb9fd
progress: show fewer digits
Without unit, show up to 99999 "raw" (5 digits). After that, prefer to
show the number as less than 1000 per unit and use single decimal
fraction. Like '123.4M' (spending 6 characters).

This now makes the largest possible size to show 8.0E (exabytes).

Probably makes the output easier to read.

Fixes #19431
Reported-by: Fd929c2CE5fA on github
Closes #19433
2025-11-11 16:22:34 +01:00
x2018
0dacc07969
cf-https-connect: allocate ctx at first in cf_hc_create()
Closes #19454
2025-11-11 16:18:55 +01:00
x2018
10b2dd8e6b
krb5_sspi: unify a part of error handling
Closes #19452
2025-11-11 16:17:53 +01:00
x2018
3f1a8dbb98
rustls: fix a potential memory issue
Closes #19425
2025-11-11 16:16:23 +01:00
Daniel Stenberg
c545e10fa7
sftp: fix range downloads in both SSH backends
When asking for the last N bytes of a file, and that size was larger
than the file size, it would miss the first byte due to a logic error.

The fixed range parser is now made a common function in the file now
renamed to vssh.c (from curl_path.c) - used by both backends.

Unit test 2605 verifies the parser.

Reported-by: Stanislav Fort (Aisle Research)
Closes #19460
2025-11-11 14:51:22 +01:00
Daniel Stenberg
7e87255020
socks_sspi: use free() not FreeContextBuffer()
The memory is allocated with malloc().

This reverts commit 1d01d4975f.

Reported-by: Stanislav Fort (Aisle Research)
Closes #19445
2025-11-10 13:39:22 +01:00
x2018
323b33d51f
digest_sspi: properly free sspi identity
Closes #19426
2025-11-10 09:20:26 +01:00
Daniel Stenberg
660f244640
urlapi: fix mem-leaks in curl_url_get error paths
Reported-by: Stanislav Fort (Aisle Research)
Closes #19440
2025-11-10 09:16:20 +01:00
x2018
baafa5ff76
schannel: fix potental memory leak of cert_store_path on four error paths
Closes #19423
2025-11-10 09:14:56 +01:00
x2018
87149c8383
mqtt: properly handle the message which exceeds maxsize
We should goto fail as topic is allocated.

Follow-up to 92fd791

Closes #19417
2025-11-10 09:07:27 +01:00
Stanislav Fort
b0aba1005b
cshutdn: acknowledge FD_SETSIZE for shutdown descriptors
In the logic called for curl_multi_fdset().

File descriptors larger than FD_SETSIZE size are simply ignored, which
of course will make things break but at least it does not trash memory.

Reported-by: Stanislav Fort (Aisle Research)
Closes #19439
2025-11-10 08:54:43 +01:00
Daniel Stenberg
00872d5c98
rtmp: fix double-free on URL parse errors
Reported-by: Stanislav Fort (Aisle Research)
Closes #19438
2025-11-10 08:53:30 +01:00
Daniel Stenberg
c791223743
setopt: disable CURLOPT_HAPROXY_CLIENT_IP on NULL
As documented.

Reported-by: Stanislav Fort (Aisle Research)
Closes #19434
2025-11-10 07:49:00 +01:00
Daniel Stenberg
92fd791f31
mqtt: reject overly big messages
Reported-by: Jiyong Yang
Closes #19415
2025-11-09 11:40:28 +01:00
x2018
a002c50510
ftp: refactor a piece of code by merging the repeated part
Closes #19411
2025-11-09 11:39:56 +01:00
x2018
1bddfe02d5
asyn-thrdd: release rrname if ares_init_options fails
Closes #19410
2025-11-09 11:35:04 +01:00
x2018
59584399a5
tftp: release filename if conn_get_remote_addr fails
Closes #19409
2025-11-09 11:32:57 +01:00
x2018
239c389836
openssl: release ssl_session if sess_reuse_cb fails
Closes #19405
2025-11-09 11:31:20 +01:00
Stefan Eissing
f55974c139
vtls: fix CURLOPT_CAPATH use
A regression in curl 8.17.0 led to a customer CAPATH set by the
application (or the curl command) to be ignored unless licurl was built
with a default CAPATH.

Add test cases using `--capath` on the custom pytest CA, generated with
the help of the openssl command when available.

Fixes #19401
Reported-by: Brad King
Closes #19308
2025-11-08 17:02:54 +01:00
x2018
9c0ccd2739
vtls: handle possible malicious certs_num from peer
For GnuTLS, mbedTLS, Rustls, Schannel and wolfSSL

This check was previously added for OpenSSL in 3df71e6dc2

Closes #19397
2025-11-08 10:33:06 +01:00
x2018
a6fcaf2958
rtmp: precaution for a potential integer truncation
On some platforms, socket descriptors may use types larger than int.
When these values exceed INT_MAX, conversion to int can truncate to
negative values causing RTMP connection failures, and even accidentally
affect other socket when high-value descriptors map to existing
lower-value sockets after integer conversion. This check ensures socket
values are within the safe range before passing them to the RTMP
library.

Closes #19399
2025-11-08 10:28:43 +01:00
Andrew
2d99cf0761
lib: fix gssapi.h include on IBMi
Fixes #19336
Closes #19337
2025-11-08 10:25:12 +01:00
Daniel Stenberg
9d1acd048c
gtls: skip session resumption when verifystatus is set
Resumed TLS sessions skip OCSP stapled-response verification. Force a
full handshake so verifystatus() runs.

Follow-up to 4bfd7a9615

Pointed out by ZeroPath
2025-11-07 14:14:54 +01:00
x2018
608d96694b
lib: refactor the type of funcs which have useless return and checks
Some internal functions always return CURLE_OK.

- Curl_http_proxy_get_destination() does that from bb4032a, (2 years
  ago) And the original inline code does not need to check the status.

- Curl_wildcard_init() does that from e60fe20. (8 years ago)

- Curl_initinfo() does that from a very beginning.

- Curl_pgrsSetDownloadCounter() did not have a return before 914e49b,
  ad051e1 recovered its content (2 years ago) but did not completely
  recovered the changes related to it.

- auth_digest_get_qop_values() does that from 676de7f.

This directly changes their type to void and cleaned the remaining
checks for their return value.

Closes #19386
2025-11-07 13:01:39 +01:00
Stefan Eissing
2684af257e
osslq: code readability
- remove assertions that are unnecessary
- lookup stream after assertions

Closes #19394
2025-11-07 12:58:26 +01:00
Daniel Stenberg
a6eaa67c55
mbedtls: fix potential use of uninitialized nread
When Curl_conn_cf_recv() returns error, the variable might not be
assigned and the tracing output may (harmlessly) use it uninitialized.

Also add a comment about the typecast from size_t to int being fine.

Pointed out by ZeroPath

Closes #19393
2025-11-07 11:09:51 +01:00
Daniel Stenberg
684af00181
setopt: when setting bad protocols, don't store them
Both CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR would
previously return error on bad input but would wrongly still store and
keep the partial (unacceptable) result in the handle.

Closes #19389
2025-11-07 08:15:42 +01:00
Viktor Szakats
ede6a8e087
conncache: silence -Wnull-dereference on gcc 14 RISC-V 64
A false positive that appeared after a recent patch for no reason.

Seen in curl-for-win unity native Linux builds on debian:testing and
debian:trixie with gcc 14.3.0 and 14.2.0 respectively:
```
-- curl version=[8.17.1-DEV]
-- The C compiler identification is GNU 14.2.0
-- Cross-compiling: Linux/x86_64 -> Linux/riscv64
[...]
lib/conncache.c: In function 'Curl_cpool_conn_now_idle':
lib/conncache.c:539:11: error: null pointer dereference [-Werror=null-dereference]
  539 |   if(!data->multi->maxconnects) {
      |       ~~~~^~~~~~~
```
Ref: https://github.com/curl/curl-for-win/actions/runs/19111497271/job/54609512969#step:3:5788

```
-- The C compiler identification is GNU 14.3.0
```
Ref: https://github.com/curl/curl-for-win/actions/runs/19111497271/job/54609512899#step:3:5801

Patch confirmed silencing:
https://github.com/curl/curl-for-win/actions/runs/19112580362/job/54613288202

Follow-up to fbc4d59151 #19271

Closes #19378
2025-11-06 11:42:34 +01:00
Viktor Szakats
8e6149598b
gnutls: report accurate error when TLS-SRP is not built-in
With GnuTLS 3.8.0+ the build-time SRP feature detection always succeeds.
It's also disabled by default in these GnuTLS versions.

When using TLS-SRP without it being available in GnuTLS, report
the correct error code `CURLE_NOT_BUILT_IN`, replacing the out of memory
error reported before this patch.

Also add comments to autotools and cmake scripts about this feature
detection property.

Detecting it at build-time would need to run code which doesn't work
in cross-builds. Once curl requires 3.8.0 as minimum, the build-time
checks can be deleted.

```
# before:
curl: (27) gnutls_srp_allocate_client_cred() failed: An unimplemented or disabled feature has been requested.
# after:
curl: (4) GnuTLS: TLS-SRP support not built in: An unimplemented or disabled feature has been requested.
```

Ref: dab063fca2
Ref: a21e89edac

Closes #19365
2025-11-06 11:42:34 +01:00
Daniel Stenberg
6d7e924e80
checksrc.pl: detect assign followed by more than one space
And fix some code previously doing this.

Closes #19375
2025-11-05 15:18:28 +01:00
Daniel Stenberg
a8bef39036
openssl: remove code handling default version
Since it is no longer actually kept as default internally, that's just
dead code.

Follow-up to 9d8998c994
Closes #19354
2025-11-05 14:14:58 +01:00
x2018
2db36f11b8
gtls: add return checks and optimize the code
This commit does the following things:

1. Update the description of gtls_init()

2. In gtls_client_init(), check the invaild SSLVERSION at first. Note
   that this part refactors the duplicate/incompatible checks and removes
   the useless local variable `sni`.

3. Check the return value of gnutls_ocsp_resp_init(). Although the
   original code is safe because gnutls_ocsp_resp_import() will check
   the validity of `ocsp_resp`, it is better to catch the error in time
   and record the proper message to output log.

Closes #19366
2025-11-05 14:09:34 +01:00