作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望 address sanitizer 在捕获到某些东西时中止。我认为它被设计为默认执行此操作,但它似乎对我不起作用。我还尝试了 ASAN_OPTIONS=halt_on_error=1
但没有效果。以下是详细信息:
在我从事的一个项目中,我们使用了地址清理器,并且它在数周内发出此警告/错误而没有人意识到:
runtime error: null pointer passed as argument xx, which is declared to never be null
尽管被称为运行时错误,但它不会停止程序或导致错误的退出代码。这是一个简单的程序来演示它:
/*
gcc -fsanitize=address,undefined \
-Wformat \
-Werror=format-security \
-Werror=array-bounds \
-g -o xasan xasan.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
fprintf(stderr, "before\n");
memcpy(NULL, argc > 1 ? "" : NULL, argc > 1 ? 1 : 0);
fprintf(stderr, "after\n");
return 0;
}
argc 技巧只是为了让 gcc 不优化 memcpy 调用,基本上在我们的代码中它最终以 memcpy(dst, NULL, 0)
结束,这会导致运行时错误/警告.
我希望在运行时错误后不会输出“after”,但它会输出并且程序退出代码为 0。这是一个错误吗?手册上说它应该停止。
最佳答案
如果不想重新编译,也可以使用export UBSAN_OPTIONS=halt_on_error=1
运行。
关于c - gcc ASAN 不会因所谓的运行时错误而停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40644715/
我是一名优秀的程序员,十分优秀!