-1

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?

BHYCHIK
  • 108
  • 9
  • Please state where OpenSSL is located; and show your compile and link commands. You don't need to show all the source files being compiled; just a few so we can see how you are compiling. – jww Jun 03 '17 at 20:01
  • Related, there's some opportunity for improvement with `SSL_CTX_new(SSLv23_client_method ())`. Take a look at [TLS Client](https://wiki.openssl.org/index.php/SSL/TLS_Client) on the OpenSSL wiki. It does a lot more with a SSL context. – jww Jun 03 '17 at 23:40
  • This may be related... OpenSSL had an issue with 1.1.0 Master recently. It looks like it was fixed quickly, but it affected some Debian systems in the wild. I'm guessing those affected have Testing or Proposed enabled. See [Issue 3615, thread issues on thread termination](https://github.com/openssl/openssl/issues/3615). – jww Jun 05 '17 at 12:26

2 Answers2

1

You need to call SSL_library_init() before SSL_load_error_strings()

Oleg
  • 726
  • 5
  • 11
  • It doesn't help. Just another core dump: Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007f646c141a4a in pthread_rwlock_rdlock () from /lib64/libpthread.so.0 #0 0x00007f646c141a4a in pthread_rwlock_rdlock () from /lib64/libpthread.so.0 #1 0x00007f645c316d3f in ?? () from /usr/lib64/libssl.so.10 #2 0x00007f645c317009 in SSL_COMP_get_compression_methods () from /usr/lib64/libssl.so.10 #3 0x00007f645c31e7d9 in SSL_library_init () from /usr/lib64/libssl.so.10 #4 0x00007f644f4384df in ConnectionInit (verbose=0) at connection.c:76 –  BHYCHIK Jun 03 '17 at 12:47
  • Are you sure that you run the program with the same openssl libs that you built with? – Oleg Jun 03 '17 at 14:08
  • At least it doesn't core if i recompile program without *.pb.cc file. How can protobuf files affect libssl? –  BHYCHIK Jun 03 '17 at 14:14
1

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.

Kenton Varda
  • 41,353
  • 8
  • 121
  • 105