asyn-thread: check thread_data->init in Curl_resolver_getsock

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
This commit is contained in:
Weng Xuetian 2025-03-22 22:42:26 -07:00 committed by Daniel Stenberg
parent f68eae250b
commit 46c6ca789e
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View 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;
}