问题标签 [sanitizer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
359 浏览

gdb - 在 GDB 中,使用 Clang 和 MemorySanitizer,如何检索触发错误的地址?

我正在使用 Clang & MemorySanitizer 并且由于内联汇编而得到了一些误报。内联汇编代码初始化一些随后使用的内存,但 MemorySanitizer 将其视为未初始化值的使用。

我正在尝试编写一个小的 GDB 脚本来过滤误报。我在 __msan_warning_noreturn 上放置了一个断点,它是在 MemorySanitizer 中打印错误和保释的函数。但是,我找不到一种简单的方法来检索触发错误的地址。

如何找到触发错误的地址?

我正在研究 X64 架构、linux、clang-3.8

谢谢你。

0 投票
1 回答
1824 浏览

gcc - 在 gcc 中默认启用 AddressSanitizer

为了能够调试和模糊整个 Linux 发行版,我想将 ASAN(AddressSanitizer,https: //en.wikipedia.org/wiki/AddressSanitizer )设置为 gcc 的默认选项。所以通常要达到我想要的,一般我在编译一个linux包之前设置以下变量:

并尝试编译并运行我的代码。我想让它默认为 gcc。

一种选择是使用规范文件:https ://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html 。但是我没有找到一种方法来设置“捕获所有规则”来编译和链接我所有的 c/c++ 代码与 AddressSanitizer。

我的问题是:

  • 任何示例如何使用规范文件来做到这一点?
  • 这是最好的方法吗?
  • 还有其他替代方法吗?
0 投票
1 回答
4768 浏览

gcc - 如何在 AddressSanitizer 错误时生成核心转储

我像这样编译我的代码以启用 Asan:

但它从不生成核心转储,以便我稍后可以检查错误的详细信息。我怎样才能生成它?

0 投票
1 回答
2154 浏览

gcc - 将功能列入黑名单的 gcc (4.8.3) 消毒剂选项

我正在 gcc 4.8.3 上编译我的代码。我已启用-fsanitize=address选项。但是我的程序在启动过程中退出,在 3rd 方库代码中抛出全局缓冲区溢出错误。所以我试图跳过这个函数(或调用者函数)的消毒剂。我试过__attribute__((no_sanitize("address")))了,但编译器会抛出警告,‘no_sanitize’ attribute directive ignored 即使尝试过-fsanitize-recover=address,但地址上似乎不支持恢复。任何人都可以帮助我如何让我的程序在第一个错误后继续运行,或者黑名单功能跳过清理?

编辑

0 投票
1 回答
330 浏览

c++ - std::vector 的手动中毒

在下面的代码片段中,有一个并非微不足道的错误,但我希望像 AddressSanitizer 这样的工具能够捕获它。

当对向量进行范围限定并在范围之外打印时,catch 引用会抛出错误 use-heap-after-free。

但是当没有范围时,std::vector实现可能不会在 pop_back 之后释放内存,因此引用仍然指向有效内存。

我四处搜索,发现您可以手动毒化内存,我想知道这是否已在 STL 中实现(https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning

0 投票
1 回答
552 浏览

address-sanitizer - 地址消毒剂的假阴性?

考虑下面的代码。当我使用地址清理程序编译和运行它时,没有显示错误。但是应该有一个错误,即分配/访问超出范围的内存位置?为什么地址消毒剂没有检测到它?

谢谢!

0 投票
2 回答
18115 浏览

gdb - 原因:AddressSanitizer:SEGV 位于未知地址(空指针)

我需要一些建议如何识别段错误的来源。

用 ASAN 编译:

从 gdb 开始:

1. 编辑:

上面的输出是针对 64 位 (x86_64) 编译的,在 32 位上会生成以下输出:

2.编辑:

不确定这意味着什么/为什么会导致段错误?

0 投票
1 回答
1915 浏览

c++ - 使用虚拟继承的未对齐地址

以下显然有效的代码使用 UndefinedBehaviorSanitizer 清理程序产生未对齐的地址运行时错误。

在 macbook 上编译和执行 clang++ -fsanitize=undefined --std=c++11 ./test.cpp && ./a.out 会产生输出 runtime error: constructor call on misaligned address 0x7fe584500028 for type 'C', which requires 16 byte alignment [...]

我想了解错误发生的方式和原因。

0 投票
1 回答
1807 浏览

clang - 如何使 MemorySanitizer 在一个错误后不停止

Clang 的文档说“默认情况下,MemorySanitizer 在第一个检测到的错误时退出。”

有人知道如何使 MemorySanitizer 不会因错误而停止吗?上面这句话暗示有办法,但我在文档中没有找到任何东西。

0 投票
1 回答
1435 浏览

python - How to catch errors raised by AddressSanitizer in C++ libraries accessed via python extension

I have a python module that uses an external C++ library using a C++ extension build with distutils. When I compile the C++ library with the address sanitizer, -fsanitize option of GCC, I get a segfault when running unit tests. Now, initially I thought that it was because me using different compiler options for the two binaries, the C++ python extension and the library but now I am more and more convinced that this is because the address sanitizer found an error in the library and triggered a seg fault, as explained here. This is also supported by the fact that if I compile the C++ library without the address sanitizer, everything works fine. When I run unit tests, the program outputs very little information:

Even looking at the core dump I was able to find only a stack trace pointing to the C++ library but no mention of address sanitizer.

I have tried to use ASAN_OPTIONS to redirect the sanitizer output to a file but the sanitizer apparently does not pick up the options:

What strategy should I take here to confirm that the seg fault coms from the sanitizer and possibly discover what kind of error it is?