【问题标题】:Program cores in openssl when i link it with protobuf-generated file当我将它与 protobuf 生成的文件链接时,openssl 中的程序核心
【发布时间】:2017-06-03 12:06:16
【问题描述】:

我在文件中的属性构造函数“ConnectionInit”中有这样的代码,用C编写。

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

当我将它与 protobuf 生成的 pb.cc 文件链接时(不调用它的代码,只是链接),它以这样的转储为核心:

#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

我检查了 protobuf 是否使用 libssl。但事实并非如此。 *.pb.cc 文件如何影响我的 openSSL 初始化?

【问题讨论】:

  • 请说明OpenSSL的位置;并显示您的编译和链接命令。您不需要显示所有正在编译的源文件;只是一些,所以我们可以看到你是如何编译的。
  • 相关,SSL_CTX_new(SSLv23_client_method ()) 有一些改进的机会。查看 OpenSSL wiki 上的 TLS Client。它在 SSL 上下文中做得更多。
  • 这可能是相关的... OpenSSL 最近遇到了 1.1.0 Master 的问题。看起来它很快就被修复了,但它影响了一些 Debian 系统。我猜那些受影响的人启用了测试或提议。见Issue 3615, thread issues on thread termination

标签: c openssl protocol-buffers core protobuf-c


【解决方案1】:

你需要在SSL_load_error_strings()之前调用SSL_library_init()

【讨论】:

  • 没用。只是另一个核心转储:程序以信号 SIGSEGV 终止,分段错误。 #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 在 ConnectionInit (verbose=0) at connection.c:76
  • 您确定运行程序时使用的 openssl 库与您构建时使用的相同吗?
  • 如果我在没有 *.pb.cc 文件的情况下重新编译程序,至少它不会成为核心。 protobuf 文件如何影响 libssl?
【解决方案2】:

protobuf 文件的存在并不是导致崩溃的原因。更有可能的是,您在某处有一个微妙的错误导致无效的内存访问。巧合的是,当你的程序在没有 .pb.cc 文件的情况下编译时,内存访问不会造成任何伤害,但是当你添加 .pb.cc 文件时,有些东西会移动,现在糟糕的内存访问是造成伤害。可能您会发现对代码的其他小改动也会导致 bug 来来去去。

要调试内存违规,我强烈建议使用 Valgrind。您所要做的就是安装 Valgrind 并运行valgrind myprogram,它会告诉您非法内存访问发生在哪里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2012-03-09
    相关资源
    最近更新 更多