Subject: Re: libssh crash on Mac

Re: libssh crash on Mac

From: Leo <leo.r_at_rogers.com>
Date: Mon, 19 Aug 2019 01:50:16 -0400

On 8/11/19 6:48 PM, Peter Stuge wrote:
> Hi Leo,
>
> Leo wrote:
>> Now when I try to connect to SFTP site, the crash produces the following
>> output in Xcode debugger:
>>
>> openssl.c > _libssh2_openssl_crypto_init()
>>
>>
>> #if OPENSSL_VERSION_NUMBER >= 0x10100000L && \
>> ?????? !defined(LIBRESSL_VERSION_NUMBER)
>> ?????? #ifndef OPENSSL_NO_ENGINE
>> ?????????????? ENGINE_load_builtin_engines();?????????????????????????????????? <-- Thread 8:
>> EXC_BAD_ACCESS (code=1, address=0x116)
>> ?????????????? ENGINE_register_all_complete();
>> ?????? #endif
>>
> I guess that OpenSSL was somehow already initialized, and the crash
> happens becuse OpenSSL does not support being initialized twice.
>
> If this is the case, please move or add the libssh2_init() call into your
> application startup, immediately on startup, before any user interaction.
>
> Then only call libssh2_session_init() in your SFTP constructor.
>
> Let me know how it goes.
>

Thanks Peter,

I followed your suggestion...

I added the libssh2_init() call to my app startup, which resulted in the
same crash BUT the macOS crash report produced this time contained some
info that nudged me to the right direction - which eventually helped
solve the issue.

Bottom line: the issue is solved - and I'm grateful for all the feedback
I received here.

Now, I don't have a single answer as to what caused the issue - as it
seems to be different for two Xcode projects of the same app (which
contain different versions of libssh2). I hope to find the least
confusing way of describing it, if anyone is curious:

Last year, I adopted a new licensing system (namely SoftwareKey.com -
which is a great licensing platform btw). The aforementioned crash log
mentioned the new licensing framework (.framework) I'm using in my apps.

I went through SoftwareKey's downloads again and found out that they
specifically mention that their libraries use libssl/libcrypto (as well
as libcurl and libxml). And that it can cause conflicts if the host app
is also using those libraries. For which purpose they also include a
"no-dependencies" .a library which, naturally, doesn't include those
3rd-party libs - and will rely on those linked to the host app.

I didn't use that library. I was using their .framework framework in all
apps (which framework includes all 3rd-party dependencies).

While it sounds like the obvious answer to my issue, it's only partially so.

After hours of testing I now have two cases:

CASE 1

-My original Xcode project which uses libssh2-1.4.3 (in a form of a
folder with source files)

-I replaced the licensing .framework with their "no-dependencies" .a lib.

-It SOLVED the SFTP crashes issue.

-I also can build the project with or without the licensing library.

Pretty straightforward - and I'm fine with using older libssh2 version
as long as it works.

CASE 2

-My updated Xcode project with the recent version, libssh2-1.9.0, as a
.a library.

-Replacing licensing .framework with the "no-dependencies" lib does NOT
help. In fact it causes build errors that prevent from compiling the app
at all.

-If I just remove the licensing .framework without replacing it with
anything else, I still cannot build the app due to the same build
errors. That is, I can only compile the app with the licensing framework
present.

-However, I did solve the SFTP crashes in this project too - but this
time by relinking to a newer libcrypto library (something gave me a hint
that libcrypto is at fault for something).

-Therefore, I do have a working app - which, however, cannot be compiled
without the licensing framework.

If it makes any difference, the build errors I mentioned above are
related to libssl:

Undefined symbol: _EVP_CIPHER_CTX_cleanup
Undefined symbol: _EVP_CIPHER_CTX_init

I'll be in touch regarding those errors with SoftwareKey.

Thanks again for all the help!

Leo

_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2019-08-19