]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ares: handle channel being destroyed early
authorStefan Eissing <stefan@eissing.org>
Tue, 19 Aug 2025 13:46:34 +0000 (15:46 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 19 Aug 2025 15:43:33 +0000 (17:43 +0200)
We are destroying the ares channel already when we shutdown
resolving. Querying the pollset afterwards is still happening,
especially in event based processing and needs to work in the
absence of a channel.

Fixes #18317
Reported-by: Natris on github
Closes #18318

lib/asyn-ares.c
lib/asyn-base.c

index bb3f4af0b9d73c738827d31b26667f7bbadadcb3..3eb769d93471db42291ba2459fe79e8f1ba6bf1c 100644 (file)
@@ -280,8 +280,9 @@ void Curl_async_ares_destroy(struct Curl_easy *data)
 CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps)
 {
   struct async_ares_ctx *ares = &data->state.async.ares;
-  DEBUGASSERT(ares->channel);
-  return Curl_ares_pollset(data, ares->channel, ps);
+  if(ares->channel)
+    return Curl_ares_pollset(data, ares->channel, ps);
+  return CURLE_OK;
 }
 
 /*
index c0df7aac5e0c5a3a050cc54d25ceb3db4ebce1ca..eb2240b816c9a775e6e83d3a05c0ea3448a815c2 100644 (file)
@@ -91,6 +91,10 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data,
   timediff_t milli;
   CURLcode result = CURLE_OK;
 
+  DEBUGASSERT(channel);
+  if(!channel)
+    return CURLE_FAILED_INIT;
+
   bitmap = ares_getsock(channel, (ares_socket_t *)sockets,
                         CURL_ARRAYSIZE(sockets));
   for(i = 0; i < CURL_ARRAYSIZE(sockets); ++i) {
@@ -107,6 +111,8 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data,
   }
 
   timeout = ares_timeout(channel, &maxtime, &timebuf);
+  if(!timeout)
+    timeout = &maxtime;
   milli = curlx_tvtoms(timeout);
   Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
   return result;