lexiforest / curl-impersonate

An active fork of curl-impersonate with more versions and build targets.
MIT License
76 stars 15 forks source link

libcurl.dll x86_64 exception occasionally #69

Closed lifeengines closed 5 months ago

lifeengines commented 5 months ago

Has anyone encountered occasional exceptions with the libcurl.dll library in the Windows x86_64 version? Through debugging and analysis, it was found that in the function void Curl_resolver_cancel(struct Curl_easy *data) { destroy_async_data(&data->conn->resolve_async); }, the data->conn is already null. It seems that the following function is called twice:`/*

perklet commented 5 months ago
lifeengines commented 5 months ago

well,I do the test for unpatched libcurl,it's seems happen also.here is the exception shotscreen,the libcurl version is curl-8_5_0,same as curl-impersonate use.maybe this is a bug of libcurl.

无标题

I use msvc compiler,my compile command line is:

cmake .. -DZLIB_INCLUDE_DIR=../../zlib/ -DZLIB_LIBRARY=../../zlib/build/Debug/ -DUSE_NGHTTP2=ON -DNGHTTP2_INCLUDE_DIR=../../nghttp2/ -DNGHTTP2_LIBRARY=../../nghttp2/build/lib/Debug/ -DCURL_USE_OPENSSL=ON -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCURL_ENABLE_SSL=ON -DCURL_DISABLE_INSTALL=OFF -DCURL_STATIC_CRT=ON -DENABLE_UNICODE=ON -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DENABLE_IPV6=ON -DUSE_ECH=ON -DENABLE_WEBSOCKETS=ON -DBUILD_TESTING=OFF -DOPENSSL_INCLUDE_DIR=../../boringssl/include/ -DOPENSSL_CRYPTO_LIBRARY=../../boringssl/lib/ -DOPENSSL_ROOT_DIR=../boringssl/ -DBROTLI_INCLUDE_DIR=../../brotli/c/include/ -DBROTLIDEC_LIBRARY=../../brotli/lib/ -DBROTLICOMMON_LIBRARY=../../brotli/lib/ -DZstd_INCLUDE_DIR=../../zstd/include/ -DZstd_LIBRARY=../../zstd/static/

and the original release of curl-impersonate has the same exception even it's no symbol,I debugged,is't same exception position. my usage of libcurl is simple,such as:

        curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
        curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
        curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
        curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS);

        // Set lock and unlock callback functions
        curl_share_setopt(share, CURLSHOPT_LOCKFUNC, curl_lock);
        curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, curl_unlock);

and

        if (gCurlShare != nullptr)
            curl_easy_setopt(curl, CURLOPT_SHARE, gCurlShare);

nothing especially. I just patched the original code:

void Curl_resolver_cancel(struct Curl_easy *data)
{
  destroy_async_data(&data->conn->resolve_async);
}

to:

void Curl_resolver_cancel(struct Curl_easy *data)
{
if (data->conn)
  destroy_async_data(&data->conn->resolve_async);
}

seems works fine. but finally I add

-DENABLE_ARES=ON -DCARES_INCLUDE_DIR="../../c-ares/;../../c-ares/include/" -DCARES_LIBRARY=../../c-ares/lib/

to libcurl compile command line to force libcurl use c-ares to resolve DNS. seems works ok.

perklet commented 5 months ago

The latest version of curl is 8.8.0, and I'm in the progress of upgrading curl-impersonate to be based on 8.7.1, see https://github.com/yifeikong/curl-impersonate/pull/67.

If this issue can be reproduced with 8.8.0, you might want to open an issue in the curl project.