dnscache: fix locking for negative caching

Reported-by: Izan on hackerone
Closes #21209
This commit is contained in:
Daniel Stenberg 2026-04-02 22:10:33 +02:00
parent f4eddde9dc
commit 1bf663e32f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -601,6 +601,8 @@ CURLcode Curl_dnscache_add_negative(struct Curl_easy *data,
if(!dnscache)
return CURLE_FAILED_INIT;
dnscache_lock(data, dnscache);
/* put this new host in the cache */
dns = dnscache_add_addr(data, dnscache, dns_queries, NULL,
host, strlen(host), port, FALSE);
@ -608,10 +610,12 @@ CURLcode Curl_dnscache_add_negative(struct Curl_easy *data,
/* release the returned reference; the cache itself will keep the
* entry alive: */
dns->refcount--;
dnscache_unlock(data, dnscache);
CURL_TRC_DNS(data, "cache negative name resolve for %s:%d type=%s",
host, port, Curl_resolv_query_str(dns_queries));
return CURLE_OK;
}
dnscache_unlock(data, dnscache);
return CURLE_OUT_OF_MEMORY;
}