当我将它与 protobuf 生成的文件链接时,在 openssl 中编程核心

问题描述 投票:0回答:2

我在文件中的属性构造函数“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 初始化?

c openssl protocol-buffers coredump protobuf-c
2个回答
1
投票

您需要在

SSL_library_init()
之前致电
SSL_load_error_strings()


1
投票

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

要调试内存违规,我强烈建议使用 Valgrind。您所要做的就是安装 Valgrind 并运行

valgrind myprogram
,它会告诉您非法内存访问发生在哪里。

© www.soinside.com 2019 - 2024. All rights reserved.