]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
asyn-thread: check thread_data->init in Curl_resolver_getsock
authorWeng Xuetian <wengxt@gmail.com>
Sun, 23 Mar 2025 05:42:26 +0000 (22:42 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 24 Mar 2025 09:03:12 +0000 (10:03 +0100)
resolver may call destroy_async_data after the name is resolved and
corresponding socketpair is already closed at this point. Any following
call to Curl_resolver_getsock should not set the fd.

Fixes #16799
Closes #16802

lib/asyn-thread.c

index c3820e76176a3948f3b9cd367783216a0d3fd814..772b8ccabf2f326d1ef2978426c0a9c4955c6ede 100644 (file)
@@ -640,8 +640,8 @@ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
 #endif
 
 #ifdef USE_HTTPSRR_ARES
-  if(data->state.async.thdata.channel) {
-    ret_val = Curl_ares_getsock(data, data->state.async.thdata.channel, socks);
+  if(td->init && td->channel) {
+    ret_val = Curl_ares_getsock(data, td->channel, socks);
     for(socketi = 0; socketi < (MAX_SOCKSPEREASYHANDLE - 1); socketi++)
       if(!ARES_GETSOCK_READABLE(ret_val, socketi) &&
          !ARES_GETSOCK_WRITABLE(ret_val, socketi))
@@ -649,10 +649,13 @@ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
   }
 #endif
 #ifndef CURL_DISABLE_SOCKETPAIR
-  /* return read fd to client for polling the DNS resolution status */
-  socks[socketi] = td->tsd.sock_pair[0];
-  ret_val |= GETSOCK_READSOCK(socketi);
-#else
+  if(td->init) {
+    /* return read fd to client for polling the DNS resolution status */
+    socks[socketi] = td->tsd.sock_pair[0];
+    ret_val |= GETSOCK_READSOCK(socketi);
+  }
+  else
+#endif
   {
     timediff_t milli;
     timediff_t ms = Curl_timediff(Curl_now(), td->start);
@@ -666,7 +669,6 @@ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
       milli = 200;
     Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
   }
-#endif
 
   return ret_val;
 }