gpt4 book ai didi

c++ - 与第 3 方库链接导致 openssl 中出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:31 24 4
gpt4 key购买 nike

我有一个使用 OpenSSL 的第 3 方库,我还使用 Qt 网络类来访问在 https 上运行的服务。

令人费解的是,当我将我的应用程序与专有库链接时,它会在调用属于 OpenSSL 的代码中的 QSslSocket 期间出现段错误。要获得段错误,我所要做的就是链接它,而不调用库中的任何函数。当我不与图书馆链接时,一切正常。

段错误看起来像这样

Program received signal SIGSEGV, Segmentation fault.
__strcmp_ssse3 () at ../sysdeps/x86_64/multiarch/../strcmp.S:209
209 ../sysdeps/x86_64/multiarch/../strcmp.S: No such file or directory.
(gdb) bt
#0 __strcmp_ssse3 () at ../sysdeps/x86_64/multiarch/../strcmp.S:209
#1 0x00007ffff72a4a5a in getrn () from /usr/lib64/libs63lib-5.16-dynr.so.10.0
#2 0x00007ffff72a4d90 in lh_insert () from /usr/lib64/libs63lib-5.16-dynr.so.10.0
#3 0x00007ffff72391fc in OBJ_NAME_add () from /usr/lib64/libs63lib-5.16-dynr.so.10.0
#4 0x00007ffff41ddba8 in SSL_library_init () from /lib/x86_64-linux-gnu/libssl.so.1.0.0
#5 0x00007ffff6b14b12 in ?? () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#6 0x00007ffff6b16de9 in ?? () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#7 0x00007ffff6b050b9 in QSslCertificate::QSslCertificate(QByteArray const&, QSsl::EncodingFormat) () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#8 0x00007ffff6b0f429 in ?? () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#9 0x00007ffff6b1760e in ?? () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#10 0x00007ffff6b1230f in QSslSocket::QSslSocket(QObject*) () from /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4
#11 0x0000000000404438 in main (argc=1, argv=0x7fffffffdb98) at s63seg.cpp:49

这是来自 strace 的最后几行。

close(4)                                = 0
mprotect(0x7fbab8e95000, 110592, PROT_READ) = 0
munmap(0x7fbabc672000, 215488) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=215488, ...}) = 0
mmap(NULL, 215488, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7fbabc672000
close(4) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libssl.so.1.0.0", O_RDONLY|O_CLOEXEC) = 4
read(4, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20.\1\0\0\0\0\0"..., 832) = 832
fstat(4, {st_mode=S_IFREG|0644, st_size=382984, ...}) = 0
mmap(NULL, 2478288, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0x7fbab8887000
mprotect(0x7fbab88db000, 2097152, PROT_NONE) = 0
mmap(0x7fbab8adb000, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x54000) = 0x7fbab8adb000
mmap(0x7fbab8ae4000, 208, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fbab8ae4000
close(4) = 0
mprotect(0x7fbab8adb000, 12288, PROT_READ) = 0
munmap(0x7fbabc672000, 215488) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} ---

知道是什么原因造成的,或者我该如何预防?当其他任何方法都失败时,我可以将使用专有库的代码放在一个单独的可执行文件中,并使用 system() 或类似的东西调用它,但这不是一个很好的解决方案。

最佳答案

OpenSSL 的两种用途是相互冲突的。您只能有一个 CRYPTO_set_locking_callback()CRYPTO_set_id 和其他回调函数的实现。同一进程中的两个 OpenSSL 用户必须在这些事情上进行合作。

关于c++ - 与第 3 方库链接导致 openssl 中出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24608955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com