690 Commits

Author SHA1 Message Date
Stefan Eissing
909af1a43b
multi: do transfer book keeping using mid
Change multi's book keeping of transfers to no longer use lists, but a
special table and bitsets for unsigned int values.

`multi-xfers` is the `uint_tbl` where `multi_add_handle()` inserts a new
transfer which assigns it a unique identifier `mid`. Use bitsets to keep
track of transfers that are in state "process" or "pending" or
"msgsent".

Use sparse bitsets to replace `conn->easyq` and event handlings tracking
of transfers per socket. Instead of pointers, keep the mids involved.

Provide base data structures and document them in docs/internal:
* `uint_tbl`: a table of transfers with `mid` as lookup key,
   handing out a mid for adds between 0 - capacity.
* `uint_bset`: a bitset keeping unsigned ints from 0 - capacity.
* `uint_spbset`: a sparse bitset for keeping a small number of
  unsigned int values
* `uint_hash`: for associating `mid`s with a pointer.

This makes the `mid` the recommended way to refer to transfers inside
the same multi without risk of running into a UAF.

Modifying table and bitsets is safe while iterating over them. Overall
memory requirements are lower as with the double linked list apprach.

Closes #16761
2025-04-17 17:28:38 +02:00
Daniel Stenberg
02e9690c3e
tests/server/dnsd: basic DNS server for test suite
Currently the DNS server only responds to A and AAAA queries. It always
responds with a fixed response: the localhost address. Three times.

It should work fine over either IPv4 or IPv6, but I don't think it
matters much for curl testing.

The idea is to allow curl tests to use "normal" DNS hostnames (using the
normal name resolving code paths) and still use the local test servers.

This setup currently only works if curl is built with c-ares because
redirecting DNS requests to our test server when using getaddrinfo() is
not easy.

This should be extended to respond to HTTPS queries as well to allow
more testing there, as c-ares is always used for that.

Test 2102 is the first test using this.

Closes #17015
2025-04-17 09:13:24 +02:00
Cole Helbling
2404a11d85
curl_get_line: handle lines ending on the buffer boundary
Very similar to 9f8bdd0eae5c1d441d9d901a7cf917a8ee215c7f, but affects
e.g. netrc file parsing.

Suggested-by: Graham Christensen <graham@grahamc.com>

Add test 744 to verify

Closes #17036
2025-04-15 17:48:32 +02:00
Daniel Stenberg
9f8bdd0eae
tool_parsecfg: make get_line handle lines ending on the buffer boundary
Add test 743 to verify.

Fixes #17030
Reported-by: Marius Kleidl
Closes #17031
2025-04-11 22:38:49 +02:00
Yedaya Katsman
8988f33f62
tests: Add https-mtls server to force client auth
- test2088 verifies that mutual tls works

This adds a new certificate to generate which has the clientAuth key
usage enabled, and uses it to connect to a https-mtls server.

Closes #16923
2025-04-07 08:46:56 +02:00
Daniel Stenberg
badfb951ec
test1658: add unit test for the HTTPS RR decoder
Made the HTTPS-RR parser a little stricter while at it.

Drop the ALPN escape handling, that was not needed.

Make the hode handle (and ignore) duplicate ALPN entries.

Closes #16972
2025-04-05 21:03:47 +02:00
Daniel Stenberg
b8bd019c6a
content_encoding: Transfer-Encoding parser improvements
- allow and ignore "identity" as an encoding

- fail if any other encoder than chunked follows after chunked

- fail on unsolicited encodings - when the server encodes but curl did
  not ask for it

Add test 1493 to 1496 to verify.

Disable test 319 as that is now broken: issue #16974

Reported-by: Jonathan Rosa
Fixes #16956
Closes #16959
2025-04-05 18:23:07 +02:00
Austin Moore
3978bd4498
aws_sigv4: merge repeated headers in canonical request
When multiple headers share the same name, AWS SigV4 expects them to be
merged into a single header line, with values comma-delimited in the
order they appeared.

Add libtest 1978 to verify.

Closes #16743
2025-03-31 00:01:55 +02:00
Daniel Stenberg
b1faac8039
multi: kill off remaining internal handles in curl_multi_cleanup
- if there are pending internal handles left in the list, they are
  leftovers (from for example Doh) and must be freed.

- unlink_all_msgsent_handles() did not properly move all msgsent
  handles over to the process list as intended

Fixes a DoH memory leak found by oss-fuzz.

Add test 2101 that can reproduce and verify.

Closes #16674
2025-03-12 09:22:32 +01:00
Daniel Stenberg
f4831daa9b
url: call protocol handler's disconnect in Curl_conn_free
For the case when the connection struct is all setup, the protocol
handler allocates data in its setup_connection function, but the
connection struct is discarded again before used further because a
connection reuse is prefered. Then the handler's disconnect function was
not previously called, which then would lead to a memory leak.

I added test case 698 that reproduces the leak and the fix.

Reported-by: Philippe Antoine
Closes #16604
2025-03-07 11:16:24 +01:00
Ethan Wilkes
fa3d1e7d43
ws: corrected curlws_cont to reflect its documented purpose
Verified in test 2311

Closes #16512
2025-03-06 16:38:05 +01:00
Daniel Stenberg
57ac8aed3f
tests/data/Makefile.am: fix trailing slash issue
Follow-up from 6758aa722ddf5a6db819b753d962

Fixes #16556
Closes #16558
2025-03-04 16:43:39 +01:00
tiymat
6758aa722d
IMAP: add CURLOPT_UPLOAD_FLAGS and --upload-flags
Set properties on the uploaded resource.

Test 3209 and 3210 verify.

Closes #15970
2025-03-04 15:21:16 +01:00
Daniel Stenberg
fb13923dd6
lib: add CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY
With this change, the argument passed to the CURLOPT_FOLLOWLOCATION
option is now instead a "mode" instead of just a boolean. Documentation
is extended to describe the two new modes.

Test 1571 to 1581 verify.

Closes #16473
2025-03-03 11:35:48 +01:00
Daniel Stenberg
6306476fc3
tool_getparam: make --url support a file with URLs
It implies -O used for each URL.

Mention in the --url documentation.

Test 488 and 489 verify.

Closes #16099
2025-02-25 09:16:54 +01:00
Daniel Stenberg
886f5dea80
test76: add test with comma-separated list of WWW-Auth methods
The support for this is not 100% but at least this works.

Closes #16425
2025-02-22 14:09:37 +01:00
Daniel Stenberg
a6e8ead533
var: add a '64dec' function that can base64 decode a string
Verified in test 455 and 487.

If the provided string cannot be base64-decoded, it will instead use
"[64dec-fail]" (without the quotes).

Documented

Ref: #16288
Closes #16330
2025-02-22 11:38:52 +01:00
Stefan Eissing
242a1439e7
vtsl: eliminate 'data->state.ssl_scache'
Keeping the relevant 'ssl_scache' in 'data->state' leads to problems
when the owner of the cache is cleaned up and this reference is left
dangling.

Remove the ref entirely and always find the ssl_scache at the current
share or multi.

Folded in #16260 (test 3208) to verify this fixes the bug with a
dangling reference when an easy handle is used with easy_perform first
and in a multi_perform after.

Ref: #16236
Closes #16261
2025-02-08 13:28:27 +01:00
Daniel Stenberg
943de21619
netrc: return code cleanup, fix missing file error
Made the netrc parser return a more consistent set of error codes and
error messages, and also return error properly if the .netrc file is
missing.

Add test 697 to verify error on missing netrc file.

Fixes #16163
Reported-by: arlt on github
Closes #16165
2025-02-06 10:34:02 +01:00
Stefan Eissing
65fca12e63
x509asn1: add parse recursion limit
For ASN.1 tags with indefinite length, curl's own parser for TLS
backends that do not support certificate inspection calls itself
recursively. A malicious server certificate can then lead to high
recursion level exhausting the stack space.

This PR limits the recursion level to 16 which should be safe on all
architectures.

Added unit test 1657 to verify behaviour.

Fixes #16135
Reported-by: z2_
Closes #16137
2025-02-03 20:10:09 +01:00
Andrew Kaster
1b740aedcd
ws: Reject frames with unknown reserved bits set
RFC 6455 Section 5.2 notes that for bits RSV1, RSV2, and RSV3 of the
framing header, a non-zero value that is not defined by a negotiated
extension MUST Fail the WebSocket connection.

Test 2310 verifies

Closes #16069
2025-01-28 10:19:39 +01:00
Jay Satiro
1a36923d73 tests: change the behavior of swsbounce
- Change the swsbounce keyword to override the part number on a
  subsequent request to the previous part number + 1.

Note the previous part number in this case is the part number that
was returned as a response to the previous request and contained
the swsbounce keyword.

Prior to this change swsbounce incremented the part number of the
subsequent request instead of overriding it, and did so in a more
limited fashion that prevented chaining swsbounce in multiple responses.

For example, if the test makes a request that causes the sws server to
return `<data>` as a response and that response contains `swsbounce`
then for the next response the sws server returns `<data1>`. If
`<data1>` also contains `swsbounce` then for the next response the sws
server now returns `<data2>` instead of the requested part.

Fixes https://github.com/curl/curl/discussions/16074
Closes https://github.com/curl/curl/pull/16085
2025-01-26 02:29:21 -05:00
Daniel Stenberg
be82a3605a
easy: make curl_easy_perform() return error if connection still there
This typically happens if CURL_CONNECT_ONLY is used and a second
curl_easy_perform() is attempted.

A connection "taken over" with CURL_CONNECT_ONLY cannot be ended any
other way than a curl_easy_cleanup() on the easy handle that holds it.

Add test 696 to verify.

Closes #16003
2025-01-14 16:32:46 +01:00
Jay Satiro
5ffc73c78e transfer: fix CURLOPT_CURLU override logic
- Change setopt and pretransfer to always reset URL related variables
  for a CURLU handle set CURLOPT_CURLU.

This change is to ensure we are in compliance with the doc which says
CURLU handles must be able to override a URL set via CURLOPT_URL and
that if the contents of the CURLU handle changes between transfers then
the updated contents must be used.

Prior to this change, although subsequent transfers appear to be
performed correctly in those cases, the work URL `data->state.url` was
not updated. CURLINFO_EFFECTIVE_URL returns data->state.url to the user
so it would return the URL from the initial transfer which was the wrong
URL. It's likely there are other cases as well.

Ref: https://curl.se/libcurl/c/CURLOPT_CURLU.html

Reported-by: Nicolás San Martín

Fixes https://github.com/curl/curl/issues/15984
Closes https://github.com/curl/curl/pull/15985
2025-01-14 04:36:13 -05:00
Patrick Monnerat
1b3f00f794
mime: explicitly rewind subparts at attachment time.
Subparts may have been previously used as a top-level mime structure and
thus not rewound.

New test 695 checks the proper functioning in these particular conditions.

Reported-by: Qriist on github
Fixes #15842
Closes #15911
2025-01-06 14:03:42 +01:00
Daniel Stenberg
0e120c5b92
netrc: 'default' with no credentials is not a match
Test 486 verifies.

Reported-by: Yihang Zhou

Closes #15908
2025-01-03 18:21:10 +01:00
Daniel Stenberg
4f920122a2
test3105: verify multi_remove_handle done twice
It should be ok.

Ref: #15852
Closes #15860
2024-12-31 12:03:51 +01:00
Daniel Stenberg
c2d37463b9
curl/var: change byte offset syntax for assignments
Follow-up to 40c264db617d0 after discussions on IRC.

The new style is

  name[0-99]=contents

and

  name[0-99]@filename

A) This does not cause the same problems with old curl versions trying
the new syntax as this way will cause old curls just fail with syntax
error and not risk using the wrong file.

B) Adds the same byte range support for "normal" assigns, which the
previous syntax did not. Thus lets a user get a partial content of a
variable etc.

Added test 790 and 791 to verify non-file assigns with ranges.

Closes #15862
2024-12-30 15:55:54 +01:00
Jay Satiro
39e21794a7 cookie: fix crash in netscape cookie parsing
- Parse the input string without modifying it.

Prior to this change a segfault could occur if the input string was
const because the tokenizer modified the input string. For example if
the user set CURLOPT_COOKIELIST to a const string then libcurl would
likely cause a crash when modifying that string. Even if the string was
not const or a crash did not occur there was still the incorrect and
unexpected modification of the user's input string.

This issue was caused by 30da1f59 (precedes 8.11.0) which refactored
some options parsing and eliminated the copy of the input string. Also,
an earlier commit f88cc654 incorrectly cast the input pointer when
passing it to strtok.

Co-authored-by: Daniel Stenberg

Closes https://github.com/curl/curl/pull/15826
2024-12-27 13:16:08 -05:00
Daniel Stenberg
9d5ecc9613
getinfo: provide info which auth was used for HTTP and proxy
CURLINFO_HTTPAUTH_USED and CURLINFO_PROXYAUTH_USED

Tested in 590 and 694

Ref: #12668
Idea-by: Ganesh Viswanathan
Closes #15450
2024-12-23 23:03:54 +01:00
Daniel Stenberg
31c6b50cb2
curl: make --etag-save acknowledge --create-dirs
Add test 693 to verify

Fixes #15730
Suggested-by: Tamir Duberstein
Closes #15732
2024-12-21 14:12:16 +01:00
Daniel Stenberg
40c264db61
curl: add byte range support to --variable reading from file
Allowing --variable read a portion of provided files, makes curl work on
partial files for any options that accepts strings. Like --data and others.

The byte offset is provided within brackets, with a semicolon separator
like: --variable name@file;[100-200]"

Inspired by #14479
Assisted-by: Manuel Einfalt

Test 784 - 789. Documentation update provided.

Closes #15739
2024-12-21 11:46:27 +01:00
Daniel Stenberg
9fce2c55d4
netrc: fix password-only entries
When a specific hostname matched, and only a password is set before
another machine is specified in the netrc file, the parser would not be
happy and stop there and return the password-only state. It instead
continued and did not return a match.

Add test 2005 to verify this case

Regression from e9b9bba, shipped in 8.11.1.

Reported-by: Ben Zanin
Fixes #15767
Closes #15768
2024-12-18 08:16:30 +01:00
Daniel Stenberg
a300879b63
curl: return error if etag options are used with multiple URLs
And document it.

Add tests 484 and 485

Fixes #15729
Reported-by: Tamir Duberstein
Closes #15731
2024-12-13 10:11:26 +01:00
Daniel Stenberg
d5c738c608
strparse: string parsing helper functions
Designed to aid converting off from sscanf parsers. sscanf is hard to
use right, easy to mess up and often makes for sloppy error checking.

The new parsers allow more exact and pedandic parsing.

This new set of functions should be possible to use (and extend) and
switch over other libcurl parser code to use going forward.

Adapts the following to use the new functions:

- altsvc.c
- hsts.c
- http_aws_sigv4.c

Bonus: fewer memory copies, fewer stack buffers.

Test: Unit test1664

Docs: docs/internals/STRPARSE.md

Closes #15692
2024-12-12 16:00:52 +01:00
Daniel Stenberg
a8c852b9a5
cookie: parse only the exact expire date
The date parser function is very forgiving and skips most "irrelevant"
characters in its hunt for a date to figure out. Therefore it is
important to make sure the date string is properly null terminated so
that it does not accidentally parse a piece of whatever text follows
after the date.

Add test483: test (overly) long expire dates in cookies

Closes #15709
2024-12-11 09:31:53 +01:00
Daniel Stenberg
0169b80e5c
curl: --continue-at is mutually exclusive with --remove-on-error
Test 482 verifies

Fixes #15645
Reported-by: Harry Sintonen
Closes #15668
2024-12-02 21:22:57 +01:00
Daniel Stenberg
ffbcde0022
curl: --continue-at is mutually exclusive with --no-clobber
Test 481 verifies

Fixes #15645
Reported-by: Harry Sintonen
Closes #15668
2024-12-02 21:22:47 +01:00
Daniel Stenberg
e9b9bbac22
netrc: address several netrc parser flaws
- make sure that a match that returns a username also returns a
  password, that should be blank if no password is found

- fix handling of multiple logins for same host where the password/login
  order might be reversed.

- reject credentials provided in the .netrc if they contain ASCII control
  codes - if the used protocol does not support such (like HTTP and WS do)

Reported-by: Harry Sintonen

Add test 478, 479 and 480 to verify. Updated unit 1304.

Closes #15586
2024-11-17 11:33:56 +01:00
Daniel Stenberg
f5c616930b
duphandle: also init netrc
The netrc init was only done in the Curl_open, meaning that a duplicated
handle would not get inited properly.

Added test 2309 to verify. It does netrc auth with a duplicated handle.

Regression from 3b43a05e000aa8f65bda513f733a

Reported-by: tranzystorekk on github
Fixes #15496
Closes #15503
2024-11-07 09:47:53 +01: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
5ee43bb82e
tests: 780 - 783, new HSTS tests
test780: verify updated HSTS data in response header

test781: HSTS update expiry, with parent includeSubDomains domain
present

test782: HSTS update expiry, with two includeSubDomains domains present

test783: HSTS update expiry, removing includesubdomains in update
2024-10-09 13:48:14 +02:00
Daniel Stenberg
b0c82239c2
tool: support --show-headers AND --remote-header-name
By keeping the headers in memory until we know the target file name,
then output them all.

Previously this option combination would cause an error.

Add test 1310 and 1492 to verify. Adjusted test 1460 to work in the new
conditions.

Closes #15110
2024-10-02 08:04:33 +02:00
Dan Fandrich
8e9a8dd978 tests: add file: tests with existing files
Windows sometimes has issues when opening the same file twice, so these
test two situations where that could potentially occur.

Reported-by: ralfjunker on github
Ref: #15043
Closes #15045
2024-09-26 10:10:36 -07:00
Daniel Stenberg
b4f7ec71ce
tool_operate: let --create-dirs work for --dump-header as well
Add test 3011 to verify

Proposed-by: Montg0mery on github
Fixes #14941
Closes #14965
2024-09-22 21:27:29 +02:00
Daniel Stenberg
0cfc7fcca1
tool_cb_wrt: use "curl_response" if no file name in URL
Use the same fallback for content-disposition cases as for regular -O

Add test692: verify -JO with URL without a file name

Reported-by: Brian Inglis
Fixes #14939
Closes #14940
2024-09-17 13:39:51 +02:00
Daniel Stenberg
aef384a7df
http: make max-filesize check not count ignored bodies
Add test 477 to verify

Reported-by: MasterInQuestion on github
Fixes #14899
Closes #14900
2024-09-14 22:51:57 +02:00
Viktor Szakats
805bbf7c55
NTLM_WB: delete remains in tests, docs updates
Also update more docs to reflect the removal of NTLM_WB.

Follow-up to 50def7c881ba560ab6e0235990e8f07fa69f4bc8 #13249
Closes #14832
2024-09-10 14:13:36 +02:00
Aki
a2bcec0ee0
openssl: fix the data race when sharing an SSL session between threads
The SSL_Session object is mutated during connection inside openssl,
and it might not be thread-safe. Besides, according to documentation
of openssl:

```
SSL_SESSION objects keep internal link information about the session
cache list, when being inserted into one SSL_CTX object's session
cache. One SSL_SESSION object, regardless of its reference count,
must therefore only be used with one SSL_CTX object (and the SSL
objects created from this SSL_CTX object).
```
If I understand correctly, it is not safe to share it even in a
single thread.

Instead, serialize the SSL_SESSION before adding it to the cache,
and deserialize it after retrieving it from the cache, so that no
concurrent write to the same object is infeasible.

Also
 - add a ci test for thread sanitizer
 - add a test for sharing ssl sessions concurrently
 - avoid redefining memory functions when not building libcurl, but
   including the soruce in libtest
 - increase the concurrent connections limit in sws

Notice that there are fix for a global data race for openssl which
is not yet release. The fix is cherry pick for the ci test with
thread sanitizer.
d8def79838

Closes #14751
2024-09-02 23:35:44 +02:00
Stefan Eissing
4cd10ee28b
POP3: fix multi-line responses
Some POP3 commands are multi-line, e.g. have responses terminated by a
last line with '.', but some are not. Define the known command
properties and fix response handling.

Add test case for STAT.

Fixes #14677
Reported-by: ralfjunker on github
Closes #14707
2024-08-30 15:38:25 +02:00