gcc ASAN不会停止声称的运行时错误
问题描述:
我希望地址清理程序在捕获某些内容时放弃。我认为这是默认设计的,但它似乎不适合我。我也试过ASAN_OPTIONS=halt_on_error=1
这没有效果。下面是详细信息:gcc ASAN不会停止声称的运行时错误
在一个项目中,我的工作,我们使用的地址清洁剂,它散发出此警告/错误数周没有人意识到这一点:
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)
这将导致运行时错误/警告。
我会期望'后'将不会在运行时错误后输出,但它是和程序退出代码是0.这是一个错误?手册说它应该停止。
答
如果您不想重新编译,也可以使用UBSAN_OPTIONS = halt_on_error = 1运行。