-
-
Notifications
You must be signed in to 8000 change notification settings - Fork 6.7k
SSL_CTX_set_quiet_shutdown in SSL_CTX_FUNCTION callback Leads To Fault in macOS #17283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If it only crashes when you call that function and not otherwise, it would indicate that the ctx pointer is correct and that the function call is what triggers the problem - after all, the context that is passed to the callback is the exact same context that libcurl uses internally itself so if it would be wrong curl would totally fail (and crash) even without the callback. This, to me, would rather suggest this is a libressl problem.
You mean invoked by something else outside of this libcurl transfer call itself? Because in curl I think this is an additional hint that this a problem in the TLS library. You could try to build curl to use another OpenSSL (fork) to see if the problem changes or goes away. I also propose that you also build curl and the TLS library with full debug symbols present so that future stack traces get more info, as they might help shed light on the problem. |
If this only crashes when you do your own |
Is your application on Mac using an SSL library different from the one libcurl is actually using? |
@jay - yes, I think that is possible. Per prior post, the Meanwhile, the Google test in the prior post - the one that generates the issue - is built using openssl. Specifically, it is built with meson, and adds Would using different libraries be an issue? |
@icing - yes, that is exactly what happens. |
|
Oh wait... I think I see your point. Maybe the issue is that CURLOPT_SSL_CTX_FUNCTION callback is invoking the openssl version of SSL_CTX_set_quiet_shutdown, but the sslctx point being passed to SSL_CTX_set_quiet_shutdown is a pointer to a LibreSSL SSL_CTX. Is that it? |
Yes that would cause a crash. |
I was able to verify that using an OpenSSL version of libcurl, i.e. not a LibreSSL version, removed the crash. For the record, to install the OpenSSL version of libcurl: Thanks so much for the help! |
I did this
On macOS, when an
SSL_CTX_new
openSSL call is made prior to callingcurl_easy_perform
, and anCURLOPT_SSL_CTX_FUNCTION
callback is provided , and the callback invokesSSL_CTX_set_quiet_shutdown
, there is intermittently a Fault, for instance a Seg Fault, duringcurl_easy_perform
or after thecurl_easy_perform
returns.OS Version: Principally macOS 15.4.1 on M3 silicon.
Also fails intermittently on macOS 13 and macOS 14
Does NOT fail on Linux, nor on Windows (tested on multiple versions of each).
Libcurl version:
Frequency of Fault: The frequency seems sensitive to small changes in the code, but typically occurs between 1% and 20% of the test runs.
URL/protocol. Protocol is HTTPS. The issue is seen whether the target is a localhost server or (as in example code below) google.com.
Possible incorrect sslctx pointer in callback
In the example test code provided below,
SSL_CTX_set_quiet_shutdown
sets the quiet-shutdown flag to 1. However, even if theSSL_CTX_set_quiet_shutdown
writes 0 instead of 1, the Fault will still be seen from time to time. This is odd, since 0 is supposed to be the default value.If
SSL_CTX_get_quiet_shutdown
is invoked in the callback, it sometimes returns an obviously invalid value, such as a large negative number (a value of 0 or 1 is expected).Given these two data points, we may speculate that the sslctx pointer passed to the callback is invalid in some way, and so when we write to the object
sslctx
is pointing too we may corrupt the memory heap.Other Observations
If we comment out the
SSL_CTX_set_quiet_shutdown
in the callback, there is no Fault. It is not the callback method that leads to the Fault, it is writing to*sslctx
within the callback.The Fault only happens if openSSL's
SSL_CTX_new
is invoked prior to the curl calls. Otherwise, there is no Fault.Here is a Google Test that generates the issue for us.
Here is a stack trace of the Fault itself. BTW, the location of the Fault seems to vary, but it usually is something to do with initialization, or memory free or cleanup or similar.
Thanks in advance.
I expected the following
No Fault/crash
curl/libcurl version
operating system
macOS 15
The text was updated successfully, but these errors were encountered: