url: dns_entry related improvements

Replace Curl_resolv_unlock() with Curl_resolv_unlink():

-replace inuse member with refcount in Curl_dns_entry

- pass Curl_dns_entry ** to unlink, so it gets always cleared

- solve potential (but unlikley) UAF in FTP's handling of looked up
  Curl_dns_entry. Esp. do not use addr information after unlinking an entry.
  In reality, the unlink will not free memory, as the dns entry is still
  referenced by the hostcache. But this is not safe and relying on no other
  code pruning the cache in the meantime.

- pass permanent flag when adding a dns entry instead of fixing timestamp
  afterwards.

url.c: fold several static *resolve_* functions into one.

Closes #14195
This commit is contained in:
Stefan Eissing 2024-07-12 12:46:50 +02:00 committed by Daniel Stenberg
parent 2372a5915c
commit 5a9262a333
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
14 changed files with 159 additions and 207 deletions

View file

@ -742,10 +742,8 @@ static CURLcode multi_done(struct Curl_easy *data,
data->state.done = TRUE; /* called just now! */
if(conn->dns_entry) {
Curl_resolv_unlock(data, conn->dns_entry); /* done with this */
conn->dns_entry = NULL;
}
if(conn->dns_entry)
Curl_resolv_unlink(data, &conn->dns_entry); /* done with this */
Curl_hostcache_prune(data);
/* if data->set.reuse_forbid is TRUE, it means the libcurl client has