Commit Graph

15326 Commits

Author SHA1 Message Date
Daniel Stenberg
5e2d4d7905
base64: accept zero length argument to base64_encode
We used to treat 0 as "call strlen() to get the length" for
curlx_base64_encode, but it turns out this is rather fragile as we
easily do the mistake of passing in zero when the data is actually not
there and then calling strlen() is wrong.

Force the caller to pass in the correct size. A zero length input string
now returns a zero length output and a NULL pointer.

Closes #18617
2025-09-19 22:57:20 +02:00
Daniel Stenberg
a0369e1705
gtls: avoid potential use of uninitialized variable in trace output
Reported in Joshua's sarif data

Closes #18620
2025-09-19 22:55:52 +02:00
Daniel Stenberg
fd6eb8d6e7
cookie: avoid saving a cookie file if no transfer was done
Because parts of the cookie loading happens on transfer start the
in-memory cookie jar risks being incomplete and then a save might
wrongly truncate the target file.

Added test 1902 to verify.

Reported-by: divinity76 on github
Fixes #18621
Closes #18622
2025-09-19 16:40:20 +02:00
Daniel Stenberg
1055864b03
telnet: make printsub require another byte input
Reported in Joshua's sarif data

Closes #18618
2025-09-19 14:40:09 +02:00
Daniel Stenberg
df60e8fe70
cf_socket_recv: don't count reading zero bytes as first byte
Reported in Joshua's sarif data

Closes #18615
2025-09-19 14:39:15 +02:00
Daniel Stenberg
4f5528675a
libssh: react on errors from ssh_scp_read
Reported in Joshua's sarif data

Closes #18616
2025-09-19 14:38:20 +02:00
Viktor Szakats
0d9a07abb7
libssh2: drop two redundant null-terminations
The null-termination was first added in the initial SFTP commit in 2006:
a634f64400

At that time this was a reasonable concern because libssh2 started
null-terminating this string just one year prior, in 2005:
efc3841fd2

This fix was released in libssh2 v0.13 (2006-03-02).

curl requires libssh2 v1.2.8, making this workaround no longer necessary.

Follow-up to 9f18cb6544 #18598

Closes #18606
2025-09-19 09:46:45 +02:00
Viktor Szakats
9f18cb6544
libssh2: error check and null-terminate in ssh_state_sftp_readdir_link()
- null-terminate the result to match the other getter
  `libssh2_sftp_symlink_ex()` call.

- check negative result and bail out early.

Reported-by: Joshua Rogers

Closes #18598
2025-09-18 22:01:27 +02:00
Daniel Stenberg
54aff4db3c
tftp: check and act on tftp_set_timeouts() returning error
Reported-by: Joshua Rogers
Ref: https://github.com/curl/curl/pull/18574#issuecomment-3300183302
Closes #18603
2025-09-18 17:54:13 +02:00
Joshua Rogers
ad147ec53d
tftp: propagate expired timer from tftp_state_timeout()
When Curl_timeleft() < 0 we used to return 0, masking the expiry and
skipping the caller’s (timeout_ms < 0) path. Now we set FIN and return
the negative value so tftp_multi_statemach() aborts with
CURLE_OPERATION_TIMEDOUT as intended.

Closes #18574
2025-09-18 17:34:31 +02:00
Jay Satiro
f8175b1536 socks_sspi: Fix some memory cleanup calls
- Ensure memory allocated by malloc() is freed by free().

Prior to this change SSPI's FreeContextBuffer() was sometimes used to
free malloc'd memory. I can only assume the reason we have no crash
reports about this is because the underlying heap free is probably the
same for both.

Reported-by: Joshua Rogers

Fixes https://github.com/curl/curl/issues/18587
Closes https://github.com/curl/curl/pull/18594
2025-09-18 11:29:15 -04:00
Joshua Rogers
a80abc45a5
sasl: clear canceled mechanism instead of toggling it
Use &= ~authused in SASL_CANCEL (was ^=) to actually remove the offending
mechanism and avoid re-enabling a disabled mech on retry.

Closes #18573
2025-09-18 17:27:29 +02:00
Daniel Stenberg
44a586472b
ldap: do not base64 encode zero length string
Reported-by: Joshua Rogers
Closes #18602
2025-09-18 17:15:30 +02:00
Daniel Stenberg
232d5a2ed9
openldap: avoid indexing the result at -1 for blank responses
Reported-by: Joshua Rogers

Closes #18600
2025-09-18 16:06:33 +02:00
Daniel Stenberg
5cc2b83446
smb: adjust buffer size checks
The checks did not account for the **two byte** 16bit read so risked
reading one more byte than what actually was received.

Reported-by: Joshua Rogers

Closes #18599
2025-09-18 16:05:33 +02:00
Stefan Eissing
0f08211330
cfilter: unlink and discard
Rewrite the code that removes a filter from the connection and discards
it. Always look at the connection, otherwise it will not work of the
filter is at the top of the chain.

Change QUIC filter setup code to always tear down the chain in
construction when an error occured.

HTTP proxy, do not remove the h1/h2 sub filter on close. Leave it to be
discarded with the connection. Avoids keeping an additional pointer that
might become dangling.

Triggered by a reported on a code bug in discard method.

Reported-by: Joshua Rogers
Closes #18596
2025-09-18 12:20:26 +02:00
Joshua Rogers
4e74b9f592
socks_sspi: restore non-blocking socket on error paths
Closes #18592
2025-09-18 08:13:52 +02:00
Daniel Stenberg
a827e4294c
smtp: check EHLO responses case insensitively
Adjust test 980 to announce starttls in lowercase.

Fixes #18588
Reported-by: Joshua Rogers
Closes #18589
2025-09-18 08:02:12 +02:00
Daniel Stenberg
9236199908
setopt: make CURLOPT_MAXREDIRS accept -1 (again)
Regression from b059f7d (shipped in 8.16.0)

Reported-by: Adam Light
Fixes #18571
Closes #18576
2025-09-17 08:58:32 +02:00
Stefan Eissing
ff8dfd315c
aws-lc: re-enable large read-ahead with v1.61.0 again
AWS-LC fixed a bug with large read ahead buffers in v1.61.0. Check a
define introduced in that version to enable the large read ahead again.

AWS-LC issue: https://github.com/aws/aws-lc/issues/2650

Closes #18568
2025-09-16 16:55:11 +02:00
Daniel Stenberg
af7d67d3c0
krb5: return appropriate error on send failures
Closes #18561
2025-09-16 11:06:08 +02:00
Viktor Szakats
a4196e2249
tidy-up: whitespace
Closes #18553
2025-09-15 15:00:11 +02:00
Stefan Eissing
de3fc1d7ad
asyn-thrdd: drop pthread_cancel
Remove use of pthread_cancel in asnyc threaded resolving. While there
are system where this works, others might leak to resource leakage
(memory, files, etc.). The popular nsswitch is one example where resolve
code can be dragged in that is not prepared.

The overall promise and mechanism of pthread_cancel() is just too
brittle and the historcal design of getaddrinfo() continues to haunt us.

Fixes #18532
Reported-by: Javier Blazquez
Closes #18540
2025-09-15 09:25:43 +02:00
Daniel Stenberg
f7cac7cc07
setopt: accept *_SSL_VERIFYHOST set to 2L
... without outputing a verbose message about it. In the early days we
had 2L and 1L have different functionalities.

Reported-by: Jicea
Bug: https://curl.se/mail/lib-2025-09/0031.html
Closes #18547
2025-09-14 23:54:22 +02:00
Daniel Stenberg
16cd81ed69
urldata: FILE is not a list-only protocol
The struct field thus does not depend on the presence of it

Closes #18525
2025-09-11 22:46:42 +02:00
Daniel Stenberg
c184f464f7
CURLOPT_MAXLIFETIME_CONN: make default 24 hours
Set a default value to only reuse existing connections if less than 24
hours old. This makes the TLS certificate check get redone for the new
connection. An application can still set it to zero.

Closes #18527
2025-09-11 19:46:41 +02:00
Stefan Eissing
115fe808f2
ngtcp2: check error code on connect failure
Access the error codes of ngtcp2 when a connect attempt failes. Trace
the information for analysis. Treat errors as permanent failure by
default, trigger retrying only when the server refused without
indicating an error.

Closes #18521
2025-09-11 16:00:58 +02:00
Stefan Eissing
b178d58266
quic: fix min TLS version handling
When switching to TSLv1.2 as default in
9d8998c994, this led to an explicit
setting of 1.2 on QUIC connections when using quictls, overriding the
already set min version of 1.3.

This leads to a ClientHello with TLS 1.2+1.3 offered on a QUIC connect
which is rejected by the Caddy server. Using ngtcp2 with OpenSSL 3.5+,
GnuTLS or AWS-LC is not affected.

Fixes #18518
Reported-by: fds242 on github
Closes #18520
2025-09-11 15:59:00 +02:00
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