From: Daniel Stenberg Date: Thu, 9 Oct 2025 07:07:27 +0000 (+0200) Subject: hostip: don't store negative resolves due unrelated errors X-Git-Tag: rc-8_17_0-1~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0db5f12b15aeaa7eec42463ff26c2c59898f3ab;p=thirdparty%2Fcurl.git hostip: don't store negative resolves due unrelated errors Like for: - OOM - resolver_start() returns error - DoH has problems Fixes #18953 Fixes #18954 Reported-by: Joshua Rogers Closes #18958 --- diff --git a/lib/hostip.c b/lib/hostip.c index ceea189732..a6531c3171 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -846,6 +846,7 @@ CURLcode Curl_resolv(struct Curl_easy *data, int respwait = 0; bool is_ipaddr; size_t hostname_len; + bool keep_negative = TRUE; /* cache a negative result */ #ifndef CURL_DISABLE_DOH data->conn->bits.doh = FALSE; /* default is not */ @@ -887,8 +888,10 @@ CURLcode Curl_resolv(struct Curl_easy *data, st = data->set.resolver_start(resolver, NULL, data->set.resolver_start_client); Curl_set_in_callback(data, FALSE); - if(st) + if(st) { + keep_negative = FALSE; goto error; + } } /* shortcut literal IP addresses, if we are not told to resolve them. */ @@ -947,10 +950,11 @@ out: else if(addr) { /* we got a response, create a dns entry, add to cache, return */ dns = Curl_dnscache_mk_entry(data, addr, hostname, 0, port, FALSE); - if(!dns) - goto error; - if(Curl_dnscache_add(data, dns)) + if(!dns || Curl_dnscache_add(data, dns)) { + /* this is OOM or similar, don't store such negative resolves */ + keep_negative = FALSE; goto error; + } show_resolve_info(data, dns); *entry = dns; return CURLE_OK; @@ -966,7 +970,8 @@ error: Curl_resolv_unlink(data, &dns); *entry = NULL; Curl_async_shutdown(data); - store_negative_resolve(data, hostname, port); + if(keep_negative) + store_negative_resolve(data, hostname, port); return CURLE_COULDNT_RESOLVE_HOST; } @@ -1550,7 +1555,8 @@ CURLcode Curl_resolv_check(struct Curl_easy *data, result = Curl_async_is_resolved(data, dns); if(*dns) show_resolve_info(data, *dns); - if(result) + if((result == CURLE_COULDNT_RESOLVE_HOST) || + (result == CURLE_COULDNT_RESOLVE_PROXY)) store_negative_resolve(data, data->state.async.hostname, data->state.async.port); return result;