BHYCHIK
BHYCHIK

Reputation: 118

Program cores in openssl when i link it with protobuf-generated file

I have such code in attribute constructor function "ConnectionInit" in file, written in C.

SSL_load_error_strings();
SSL_library_init();
DefaultSSLConnectionContext = SSL_CTX_new(SSLv23_client_method ());

When i link it with protobuf-generated pb.cc file (without calling it's code, just link), it cores with such dump:

#0 0x00007f269454acea in pthread_rwlock_wrlock () from /lib64/libpthread.so.0
#0 0x00007f269454acea in pthread_rwlock_wrlock () from /lib64/libpthread.so.0
#1 0x00007f26843dbcbb in ?? () from /usr/lib64/libcrypto.so.10
#2 0x00007f26843dba0b in ?? () from /usr/lib64/libcrypto.so.10
#3 0x00007f26843db3bc in ?? () from /usr/lib64/libcrypto.so.10
#4 0x00007f26843dc9b1 in ERR_load_ERR_strings () from /usr/lib64/libcrypto.so.10
#5 0x00007f26843dcb99 in ERR_load_crypto_strings () from /usr/lib64/libcrypto.so.10
#6 0x00007f268471ced9 in SSL_load_error_strings () from /usr/lib64/libssl.so.10
#7 0x00007f26778414f9 in ConnectionInit (verbose=0) at connection.c:79
#8 0x00007f2695a5f74f in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
#9 0x00007f2695a63f75 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#10 0x00007f2695a5f366 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#11 0x00007f2695a6371a in _dl_open () from /lib64/ld-linux-x86-64.so.2
#12 0x00007f2693fa8f66 in dlopen_doit () from /lib64/libdl.so.2
#13 0x00007f2695a5f366 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#14 0x00007f2693fa929c in _dlerror_run () from /lib64/libdl.so.2
#15 0x00007f2693fa8ee1 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2

I examined, if protobuf uses libssl. But it doesn't. How can *.pb.cc file affect my openSSL initialization?

Upvotes: -1

Views: 316

Answers (2)

Kenton Varda
Kenton Varda

Reputation: 45151

The presence of a protobuf file isn't what is causing your crash. More likely, you have a subtle bug somewhere that is making an invalid memory access. By coincidence, the memory access doesn't happen to do any harm when your program is compiled without the .pb.cc file, but when you add the .pb.cc file, some things move around, and now the bad memory access is doing damage. Probably you'd find that other small changes to your code will also cause the bug to come and go.

To debug memory violations, I highly recommend using Valgrind. All you have to do is install Valgrind and run valgrind myprogram and it will tell you where the illegal memory access is happening.

Upvotes: 1

Oleg
Oleg

Reputation: 766

You need to call SSL_library_init() before SSL_load_error_strings()

Upvotes: 1

Related Questions