]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hostip: don't store negative resolves due unrelated errors
authorDaniel Stenberg <daniel@haxx.se>
Thu, 9 Oct 2025 07:07:27 +0000 (09:07 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 9 Oct 2025 08:50:56 +0000 (10:50 +0200)
Like for:

- OOM
- resolver_start() returns error
- DoH has problems

Fixes #18953
Fixes #18954
Reported-by: Joshua Rogers
Closes #18958

lib/hostip.c

index ceea1897322afb3017b3c343f6388fc446ea274e..a6531c31711b8c04193a0f792f33fafba56b3e09 100644 (file)
@@ -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;