Commit Graph

15298 Commits

Author SHA1 Message Date
Viktor Szakats
3ba74c4395
curl_mem_undef.h: limit to CURLDEBUG for non-memalloc overrides
To fix non-`CURLDEBUG` builds on 32-bit AIX, where `fopen` is a system
macro.

Ref: #18502
Ref: 793a375ce3

Follow-up to 3bb5e58c10 #17827
Reported-by: Andrew Kirillov
Fixes #18510
Closes #18514
2025-09-10 13:08:54 +02:00
Stefan Eissing
a782867c9f
curl_easy_getinfo: error code on NULL arg
When passing an address to curl_easy_getinfo to retrieve a value and the
address is NULL, return CURLE_BAD_FUNCTION_ARGUMENT instead of
CURLE_UNKNOWN_OPTION.

Closes #18512
2025-09-10 12:44:25 +02:00
Stefan Eissing
80ac5fb2ec
easy_getinfo: check magic, Curl_close safety
Check the easy handles magic in calls to curl_easy_getinfo().
In Curl_close() clear the magic after DNS shutdown since we'd
like to see tracing for this.
When clearing the magic, also clear the verbose flag so we
no longer call DEBUGFUNCTION on such a handle.

Closes #18511
2025-09-10 12:06:16 +02:00
Ethan Everett
f4758cd524
quic: ignore EMSGSIZE on receive
Some OSes (Linux, macOS, more?) will generate an EMSGSIZE socket error
on the next recv all after receiving an ICMP Packet Too Big on an
unconnected UDP socket.

These can be safely ignored as QUIC's DPLPMTUD uses MTU probes that do
not rely on receiving ICMP packets.

Closes #18505
2025-09-10 11:51:25 +02:00
Viktor Szakats
9863599d69
lib: introduce CURL_ACCEPT()
To avoid overriding the system symbol `accept`, which is a macro on some
systems (AIX), and thus can't be called via the `(function)` PP trick.

It's also problematic to reset such macro to its original value.

Follow-up to 3bb5e58c10 #17827
Reported-by: Andrew Kirillov
Fixes #18500
Closes #18501
Closes #18502
2025-09-09 15:17:34 +02:00
Stefan Eissing
e3c06ccc66
vquic: replace assert
Replace the hard assert in case not all data is send on UDP
(which should never happen), with an error return.

Closes #18495
2025-09-08 16:05:27 +02:00
Daniel Stenberg
84db7a9eae
ws: get a new mask for each new outgoing frame
Reported-by: Calvin Ruocco
Closes #18496
2025-09-08 16:04:16 +02:00
Andrew
7c9878ff0c
curl_setup.h: include limits.h before testing for #ifndef SSIZE_MAX
Ref: 93f333c18f #18426 #18406
Fixes #18493
Closes #18494
2025-09-08 14:52:55 +02:00
Viktor Szakats
7f7db9e372
lib: fix broken link in comment 2025-09-07 19:19:05 +02:00
Viktor Szakats
b85cb8cb4e
openldap: fix -Wtentative-definition-compat
It's a `-Weverything` warning that appeared in llvm/clang 21.

```
lib/openldap.c:1297:19: warning: duplicate declaration of 'ldapsb_tls' is invalid in C++ [-Wtentative-definition-compat]
 1297 | static Sockbuf_IO ldapsb_tls =
      |                   ^
lib/openldap.c:499:19: note: previous declaration is here
  499 | static Sockbuf_IO ldapsb_tls;
      |                   ^
```

Reported-by: correctmost on github
Fixes #18470
Cherry-picked from #18477
Closes #18485
2025-09-07 12:36:44 +02:00
Stefan Eissing
0b09132877
websocket: handling of PONG frames
The auto PONG frames were inserted into the connection at the time
a PING had been decoded, irregardless if an upstream frame was just
in the middle of being assembled.

Add PONG frames only to the buffer if there is no frame currently
assemebled and, if it is, set the control frame aside. This control
frame is then added on the first opportunity of a "clean" send buffer.

There is only a single control frame set aside at a time. This means
a double PING will, when the PONG cannot be sent right away, only
send the last PONG.

I imagine this is fine. We want to prevent the endless buffering of
PONG frames on a connection where the server sends but does no receives.

Reported-by: Calvin Ruocco
Fixes #16706
Closes #18479
2025-09-05 13:17:39 +02:00
Viktor Szakats
ec9cb618a0
spacecheck: warn for 3+ empty lines in a row, fix fallouts
Closes #18478
2025-09-04 20:37:51 +02:00
Stefan Eissing
5fa4fb0c13
websocket: reset upload_done when sending data
Sending websocket data did not clear the "upload_done" flag of
the initial HTTP Upgrade request, leading to KEEP_SEND never be
cleared. This caused the socket to be polled for INOUT after all
the websocket data had been sent. A busy loop.

Closes #18476
2025-09-04 14:47:15 +02:00
Daniel Stenberg
1edead4360
rtsp: split out a subfunction from rtsp_do
Takes complexity down from 71 to 52.

Closes #18471
2025-09-04 08:31:27 +02:00
Daniel Stenberg
31659b4a7a
http_add_connection_hd: respect previous error
Pointed out by CodeSonar

Closes #18472
2025-09-04 08:26:17 +02:00
Viktor Szakats
5ef4451f7b
cmake: fix setting LTO properties on the wrong targets
Follow-up to ae1a861bd6 #17043

Closes #18469
2025-09-03 18:35:31 +02:00
Viktor Szakats
0b0f3d937c
lib: drop UNUSED_PARAM macro
Added in 2011, but has seen little use in the code. The necessary
compiler feature is missing in some compilers (e.g. MSVC), thus in most
places the portable `(void)` cast is used in addition.

Also:
- vtls/rustls: silence unused argument warning with `(void)`.
  Necessary for MSVC, for example.

Ref: ee4ed46128

Closes #18455
2025-09-03 16:33:05 +02:00
Viktor Szakats
49145249be
tidy-up: drop stray "unused" comments
Closes #18453
2025-09-03 16:31:16 +02:00
Stefan Eissing
24badd29f5
multi: limit-rate revisited
Tweaks around handling of --limit-rate:

* tracing: trace outstanding timeouts by name
* multi: do not mark transfer as dirty that have
  an EXPIRE_TOOFAST set
* multi: have one static function to asses speed limits
* multi: when setting EXPIRE_TOOFAST remove the transfers
  from the dirty set
* progress: rename vars and comment on how speed limit
  timeouts are calculated, for clarity
* transfer: when speed limiting, exit the receive loop
  after a quarter of the limit has been received, not
  on the first chunk received.
* cf-ip-happy.c: clear EXPIRE_HAPPY_EYEBALLS on connect
* scorecard: add --limit-rate parameter to test with
  speed limits in effect

Closes #18454
2025-09-03 15:53:41 +02:00
Daniel Stenberg
de86c2483f
test763: verify IDN hostname with zero width characters only
Bonus: fix memory leak in exit path from 967a626af4

Closes #18465
2025-09-03 15:49:54 +02:00
David Zhuang
c278c508e2
http: do the cookie list access under lock
A previous refactor of cookie logic changed Curl_cookie_getlist to no
longer return a list of copied cookies, but instead return a linked list
pointing to existing cookies. The returned linked list is accessed
outside of the scope of the cookie share lock in http_cookies, which
leads to issues if the shared cookie list is modified at the same time.
This is the relevant commit: be39ed1

Closes #18457
2025-09-03 12:54:31 +02:00
Daniel Stenberg
967a626af4
idn: reject conversions that end up as a zero length hostname
Reported-by: RepoRascal on hackerone
Closes #18462
2025-09-03 11:55:23 +02:00
Daniel Stenberg
f8e6e11725
parsedate: make Curl_getdate_capped able to return epoch
By returning error separately on parse errors and avoiding magic
numbers, this function can now return 0 or -1 as proper dates when such
a date string is provided.

Closes #18445
2025-09-02 07:55:34 +02:00
Stefan Eissing
4d040c71d7
Curl_http(), decomplexify
Split out adding of individual request headers into a switch. Check
the connection http version only on fresh connections, use separate
methods.

Add TE: header directly without allocation. Add bit for indicating
Connection: header has been added and custom headers should not do
that again.

Closes #18444
2025-09-02 07:54:46 +02:00
Stefan Eissing
e65dc7fa23
aws-lc: do not use large buffer
test_10_08, uploading larger files for a h2 proxy, sporadically fails
with a decrpytion error on received data in AWS-LC. The frequency can
be increased by simulated network receive blocks.

Not setting a 4 * TLS record sized buffer, leaving AWS-LC at its
default buffer size seems to mitigate this problem.

Closes #18434
2025-09-01 23:27:11 +02:00
Daniel Stenberg
5256ce229e
cw-out: add assert for data->conn
Instead of checking it runtime. CodeSonar pointed out that if it
actually CAN legitimately be NULL here, then we need to do more checks
for it...

Closes #18440
2025-09-01 08:53:39 +02:00
Viktor Szakats
598078dcf8
curl_setup.h: include stdint.h earlier
To have it included by the time checking for `SIZE_MAX` and `SSIZE_MAX`.

Ref: 93f333c18f #18426 #18406

Closes #18430
2025-08-29 21:14:35 +02:00
Stefan Eissing
fa9151b41a
cw-out: handle error codes for 0len writes
Handle errors returned by the callback the same for 0-length writes as
for all the others.

Closes #18428
2025-08-29 16:01:16 +02:00
XCas13
21c288902d
ngtcp2: handshake timeout should be equal to --connect-timeout
Default timeout is hardcoded (10 seconds) and doesn't respect
--connect-timeout parameter. In some cases 10 seconds can be not enough
or too long to "establish a connection". Moreover the non-working
--connect-timeout parameter for http3 is confusing. This change makes
the handshake timeout equal to --connect-timeout, if it's set.
Discussion is here https://github.com/curl/curl/discussions/18427

Closes #18431
2025-08-29 15:59:06 +02:00
Daniel Stenberg
93f333c18f
curl_setup: use SIZE_MAX instead of SIZE_T_MAX
As SIZE_MAX exists in C99

Assisted-by: Stefan Eissing
Assisted-by: Jay Satiro

Ref: #18406
Closes #18426
2025-08-29 09:45:06 +02:00
Viktor Szakats
7ceb9c54aa
clang-tidy: disable clang-analyzer-security.ArrayBound
It's causing false-positives with clang-tidy v21, in cases in system
headers (seen in `FD_ISSET()` with macOS SDK). In some cases in
tests/server, there was no distinct source line that was triggering it.

Example:
```
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/sys/_types/_fd_def.h:83:10: error: Potential out of bound access to 'fds_read.fds_bits' with tainted index [clang-analyzer-security.ArrayBound,-warnings-as-errors]
   83 |                 return _p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS)));
      |                        ^
[...]
/Users/runner/work/curl/curl/tests/server/socksd.c:679:5: note: Taking false branch
  679 |     if(rc < 0) {
      |     ^
```

Closes #18422
2025-08-29 03:07:42 +02:00
Daniel Stenberg
fe01ace248
cookie: simplifications
- add Curl_secure_context(), to have it determined in a single place.

- tweak the Curl_cookie_getlist() proto. Move some logic into the
  function - at is only called in a single place. Instead of forcing the
  caller to do it.

- make 'is_ip' a const

Closes #18419
2025-08-28 17:52:07 +02:00
Stefan Eissing
f08ecdc586
requests: fix uninitialized var
init char whose address is passed for a 0-length buffer, clang does not
like it

Refs #18418
Closes #18420
2025-08-28 14:58:59 +02:00
Stefan Eissing
fa3baabbd8
websocket: improve handling of 0-len frames
Write out 9-length frames to client's WRITEFUNCTION
Read 0-length frames from READFUNCTION *if* the function
started a new frame via `curl_ws_start_frame()`.

Fixes #18286
Closes #18332
Reported-by: Andriy Druk
2025-08-28 11:00:02 +02:00
Jay Satiro
cd015c8819 schannel: fix renegotiation
- Move the schannel_recv renegotiation code to function
  schannel_recv_renegotiate.

- Save the state of a pending renegotiation.

- Pre-empt schannel_recv and schannel_send to continue a pending
  renegotation.

- Partially block during renegotiation if necessary.

Prior to this change, since a1850ad7 (precedes 8.13.0), schannel_recv
did not properly complete renegotiation before attempting to decrypt
data. In some cases that could cause an error SEC_E_CONTEXT_EXPIRED.
Most of the time though DecryptMessage would succeed by chance and
return SEC_I_RENEGOTIATE which allowed the renegotiation to continue.

Reported-by: stephannn@users.noreply.github.com
Reported-by: Dustin L. Howett

Fixes https://github.com/curl/curl/issues/18029
Closes https://github.com/curl/curl/pull/18125
2025-08-27 02:10:05 -04:00
Jay Satiro
b9be9f9466 schannel: fix memory leak during handshake
Follow-up to b6a5f672 which improved the handshake procedure.

Ref: https://github.com/curl/curl/pull/18323

Closes https://github.com/curl/curl/pull/18410
2025-08-27 02:10:04 -04:00
Daniel Stenberg
0f3f6e3a93
wolfssl: simplify Curl_wssl_ctx_init
by splitting out functions for client certificate and setting min/max
TLS version

Closes #18402
2025-08-27 08:02:24 +02:00
Daniel Stenberg
5beb644661
ftp: simplify
- Avoid checking what's always true. The ftpcode pointer is always
  passed in, so use it.
- Simplified an indent level somewhat
- Split out two functions from the state machine

Closes #18403
2025-08-26 23:34:52 +02:00
Daniel Stenberg
05407422fb
socks_sspi: simplify, clean up Curl_SOCKS5_gssapi_negotiate
This function returned error on MANY places, each with its own cleanup
sequence and by the look of it almost all of them were incomplete,
making them leak resources on errors.

This take now gotos to the error label where it cleans everything up
before returning error. This also simplifies the function a lot.

Closes #18315
2025-08-26 15:01:47 +02:00
Viktor Szakats
ca6d6dcb20
openssl: assume OPENSSL_VERSION_NUMBER
It's defined in all supported OpenSSL versions and forks.

Also formatting in `md4.c`.

Closes #18388
2025-08-24 00:59:39 +02:00
Viktor Szakats
d65436d9a0
openssl: BoringSSL / AWS-LC tidy-ups
- schannel: apply BoringSSL workaround to AWS-LC too.
  Affects Schannel + AWS-LC MultiSSL builds. (not tested in CI)
  Ref: 274940d743 #2643 #2634

- curl_ntlm_core: deduplicate macro defines.

- curl_ntlm_core: document version thresholds for an AWS-LC-specific
  workaround.
  It was necessary between v1.2.0 2022-09-01 and v1.30.1 2024-06-21.
  No longer necessary since v1.31.0 2024-07-01:
  ba94617d99
  Follow-up to 34ef4fab22 #10320

- lib758: drop redundant OpenSSL version guards.
  `OPENSSL_VERSION_NUMBER > 3` automatically guards against LibreSSL,
  BoringSSL and AWS-LC.
  Ref: 6ddd8f2c0b
  Follow-up to a5f0ab7995 #18288

- dllmain, curl_sha512_256: formatting.

Closes #18387
2025-08-24 00:30:06 +02:00
Viktor Szakats
f67090679f
openssl: sync an AWS-LC guard with BoringSSL
BoringSSL always used the same type:
https://boringssl.googlesource.com/boringssl/+/103ed08549a74af9f03363c633028faf9a475066
103ed08549

But, this codepath isn't built with BoringSSL, because it defines
`OPENSSL_NO_OCSP` via `opensslconf.h`.

Also drop an out-of-place `#endif` comment.

Ref: 20f4e94eeb #11568

Closes #18384
2025-08-23 22:57:30 +02:00
Viktor Szakats
1fc622db8e
openssl: drop single-use interim macro USE_OPENSSL_SRP
Closes #18383
2025-08-23 21:32:24 +02:00
Stefan Eissing
d57cfc1a8d
asyn-thrdd: more simplifications
- use wakeup sockets non-locked.
- send wakeup notify only in normal control flow (not cancel). close
  wakeup sockets in unlink only.
- remove 5ms thread lifetime wait crutch before pthread_cancel().

Closes #18380
2025-08-23 16:25:39 +02:00
Viktor Szakats
4f0e530c77
tidy-up: formatting
Closes #18373
2025-08-23 01:12:27 +02:00
Viktor Szakats
03868ca714
asyn-thrdd: fix no HAVE_GETADDRINFO builds
mingw32ce, CM 4.4.0-arm schannel:
```
lib/asyn-thrdd.c: In function 'gethostbyname_thread':
lib/asyn-thrdd.c:349: error: too many arguments to function 'async_thrd_cleanup'
```
Ref: https://github.com/curl/curl/actions/runs/17158865566/job/48682687295?pr=18039#step:9:21

Follow-up to 88fc6c491f #18263
Closes #18371
2025-08-23 00:16:06 +02:00
Viktor Szakats
806d97d172
openssl: merge two #if blocks
Cherry-picked from #18330
Closes #18370
2025-08-22 22:52:51 +02:00
Viktor Szakats
b54039de2c
openssl: use RSA_flags() again with BoringSSL
Supported since 2017-12-18:
a0c87adbf0

Follow-up to cd276c3cca #2117

Closes #18369
2025-08-22 20:36:11 +02:00
Viktor Szakats
78f53e0460
openssl: enable HAVE_KEYLOG_CALLBACK for AWS-LC
Supported by all AWS-LC versions:
6e3f5cc7e1

Closes #18368
2025-08-22 20:36:10 +02:00
Viktor Szakats
63bf7a0898
openssl: drop redundant HAVE_OPENSSL_VERSION macro
It served as an extra guard over `OPENSSL_VERSION_STRING`.

Also, document that `OPENSSL_VERSION_STRING` is supported by OpenSSL 3+.

Closes #18367
2025-08-22 18:55:26 +02:00