- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的代码:
#include <openssl/rsa.h>
int main(){
BIGNUM *bne = NULL;
unsigned long e = RSA_F4;
RSA *r = NULL;
bne = BN_new();
BN_set_word(bne,e);
r = RSA_new();
int ret = RSA_generate_key_ex(r, 1024, bne, NULL);
const BIGNUM *n = NULL;
const BIGNUM *d = NULL;
RSA_get0_key(r, &n, NULL, &d);
BN_print_fp(stdout, n);
RSA_free(r);
BN_free(bne);
return 0;
}
我是这样编译的:
gcc -Wall -Wextra -Wl,-rpath,/home/roman/Dropbox/uni/RSA/my_work/library/lib -g sharedLibraryTest.c -o sharedLibraryTest -I/home/roman/Dropbox/uni/RSA/my_work/library/include - L/home/roman/Dropbox/uni/RSA/my_work/library/lib -lcrypto -ldl
当我使用 ./sharedLibraryTest
正常运行时,一切正常。但是,当我在 Valgrind 中运行它时,它显示 Illegal instruction (core dumped)
并且有一些我不明白的内存泄漏(我看不到)。
你知道是什么原因造成的吗?我正在运行 OpenSSL 1_1_0e。
这是 Valgrind 的输出。
$ valgrind ./sharedLibraryTest
==4500== Memcheck, a memory error detector
==4500== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4500== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==4500== Command: ./sharedLibraryTest
==4500==
vex amd64->IR: unhandled instruction bytes: 0x48 0xF 0xC7 0xF0 0x72 0x2 0xE2 0xF8
vex amd64->IR: REX=1 REX.W=1 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR: VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F
vex amd64->IR: PFX.66=0 PFX.F2=0 PFX.F3=0
==4500== valgrind: Unrecognised instruction at address 0x5026fa5.
==4500== at 0x5026FA5: OPENSSL_ia32_rdrand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4FC2B12: rand_bytes (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4EF698E: BN_rand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4EF5430: BN_generate_prime_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4FCA616: RSA_generate_key_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x400963: main (sharedLibraryTest.c:12)
==4500== Your program just tried to execute an instruction that Valgrind
==4500== did not recognise. There are two possible reasons for this.
==4500== 1. Your program has a bug and erroneously jumped to a non-code
==4500== location. If you are running Memcheck and you just saw a
==4500== warning about a bad jump, it's probably your program's fault.
==4500== 2. The instruction is legitimate but Valgrind doesn't handle it,
==4500== i.e. it's Valgrind's fault. If you think this is the case or
==4500== you are not sure, please let us know and we'll try to fix it.
==4500== Either way, Valgrind will now raise a SIGILL signal which will
==4500== probably kill your program.
==4500==
==4500== Process terminating with default action of signal 4 (SIGILL)
==4500== Illegal opcode at address 0x5026FA5
==4500== at 0x5026FA5: OPENSSL_ia32_rdrand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4FC2B12: rand_bytes (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4EF698E: BN_rand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4EF5430: BN_generate_prime_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x4FCA616: RSA_generate_key_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500== by 0x400963: main (sharedLibraryTest.c:12)
==4500==
==4500== HEAP SUMMARY:
==4500== in use at exit: 6,216 bytes in 32 blocks
==4500== total heap usage: 146 allocs, 114 frees, 14,880 bytes allocated
==4500==
==4500== LEAK SUMMARY:
==4500== definitely lost: 0 bytes in 0 blocks
==4500== indirectly lost: 0 bytes in 0 blocks
==4500== possibly lost: 0 bytes in 0 blocks
==4500== still reachable: 6,216 bytes in 32 blocks
==4500== suppressed: 0 bytes in 0 blocks
==4500== Rerun with --leak-check=full to see details of leaked memory
==4500==
==4500== For counts of detected and suppressed errors, rerun with: -v
==4500== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction (core dumped)
最佳答案
这看起来像是 valgrind 中的一个已知错误,已经有一个 patch。 .
问题是 valgrind 不支持 libcrypto 使用的 CPU 指令。解决方案是不告诉 libcrypto 该指令可用。
内存泄漏很可能是异常终止的结果。即不调用不同对象的析构函数。
解决方案
获取最新稳定版
应用补丁
从在线仓库获取SVN版本
关于c - 由于 RDRAND,OpenSSL 在 Valgrind 下生成核心转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45370852/
我希望 valgrind 在发现第一个错误时停止并退出。 请勿推荐 --vgdb-error=1 :它不会退出 valgrind。您必须连接 gdb 并从那里终止。 --db-attach : 在最近
有人可以快速解释 Valgrind 的工作原理吗?一个例子:它如何知道内存何时被分配和释放? 最佳答案 Valgrind 基本上在“沙箱”中运行您的应用程序。在此沙箱中运行时,它能够插入自己的指令来进
我有一个因 SIGSEGV 而崩溃的应用程序。 --20183-- VALGRIND INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) -
我有一个因 SIGSEGV 而崩溃的应用程序。 --20183-- VALGRIND INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) -
我想使用 valgrind 检查长时间运行的进程是否存在内存泄漏。我怀疑我所追求的内存泄漏可能仅在执行几个小时后才会发生。我可以在 valgrind 下运行应用程序并获取 valgrind 日志,但这
我想用 valgrind 检查一个长时间运行的进程是否有内存泄漏。我怀疑我所追求的内存泄漏可能仅在执行数小时后才会发生。我可以在 valgrind 下运行应用程序并获得 valgrind 日志,但这样
如何在不通过 valgrind 命令选项启动它的情况下对每个 Process 实例执行 valgrind memcheck。 有没有办法将监控选项保存在进程中,而不是每次都使用 valgrind 命令
我使用了“--trace-children=yes”选项,我还使用了“--trace-children-skip=patt1,patt2,...”选项(过滤掉噪音过程)。但它对我来说仍然很慢,我的多进
我从 Valgrind 得到以下日志: MPK ==5263== 4 bytes in 1 blocks are still reachable in loss record 1 of 84 ==52
如何在 Valgrind 抑制文件中添加注释? 我需要为一个大型项目维护一个 Valgrind 抑制文件。我们从我们链接到的工具中过滤无法修复的错误。随着工具的新版本发布,此文件可能需要随着时间的推移
我有一个大程序要运行。使用 valgrind 需要几个小时才能运行。我听说有一些东西可以让我们为程序中的特定函数调用 valgrind。其余程序将正常执行(没有 valgrind env)。 任何人都
我可以用 valgrind 检测整数溢出缺陷吗?里面的哪个工具可以做到这一点? 最佳答案 Valgrind 没有可以检测整数溢出的工具。 您可能会使用 gcc 选项捕获这些错误: -ftrapv Th
我有一个简单的程序: int main(void) { const char sname[]="xxx"; sem_t *pSemaphor; if ((pSemaphor = sem_o
如何让 Valgrind 准确显示错误发生的位置?我编译了我的程序(通过 PuTTy 在 Windows 机器上通过 Linux 终端)添加了 -g 调试选项。 当我运行 Valgrind 时,我得到
或者最好是全部,而不仅仅是我的代码?我的程序使用 Gtk、Loudmouth 和其他一些东西,而这两个(以及它们背后的一些,libgcrypto、libssl)本身导致了如此多的错误,以至于我无法检测
我想尝试使用 valgrind 进行一些堆损坏检测。通过以下腐败“单元测试”: #include #include #include int main() { char * c = (ch
我看过类似的问题here ,但我的问题是我没有编辑 default.supp 文件的权限。例如,Valgrind 中是否有任何忽略所有抑制文件的命令行选项? 最佳答案 在 Valgrind 3.10.
我在一个运行无限循环的程序上使用 valgrind。 由于memcheck在程序结束后显示内存泄漏,但由于我的程序有无限循环,它永远不会结束。 那么有什么方法可以强制从 valgrind 时不时地转储
我一直在尝试使用 valgrind 查找一些可疑的内存错误。 在被分析的程序甚至到达我希望分析的点之前,它会因为对 mmap 的调用开始失败而退出。当它不在 valgrind 下时,这些调用会成功。
由于 OpenSSL 使用未初始化的内存,因此对使用 openldap2 的 libldap 的程序进行 Valgrind 是一件苦差事。存在一个 --ignore-fn选项,但仅适用于 Valgri
我是一名优秀的程序员,十分优秀!