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
This commit is contained in:
Stefan Eissing 2025-03-25 09:47:40 +01:00 committed by Daniel Stenberg
parent 02e9690c3e
commit 909af1a43b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
41 changed files with 2553 additions and 424 deletions

View file

@ -47,7 +47,8 @@ void Curl_multi_connchanged(struct Curl_multi *multi);
/* Internal version of curl_multi_init() accepts size parameters for the
socket, connection and dns hashes */
struct Curl_multi *Curl_multi_handle(size_t hashsize,
struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size,
size_t hashsize,
size_t chashsize,
size_t dnssize,
size_t sesssize);
@ -163,9 +164,13 @@ CURLcode Curl_multi_xfer_sockbuf_borrow(struct Curl_easy *data,
void Curl_multi_xfer_sockbuf_release(struct Curl_easy *data, char *buf);
/**
* Get the transfer handle for the given id. Returns NULL if not found.
* Get the easy handle for the given mid.
* Returns NULL if not found.
*/
struct Curl_easy *Curl_multi_get_handle(struct Curl_multi *multi,
curl_off_t id);
struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi,
unsigned int mid);
/* Get the # of transfers current in process/pending. */
unsigned int Curl_multi_xfers_running(struct Curl_multi *multi);
#endif /* HEADER_CURL_MULTIIF_H */