gpt4 book ai didi

c - gcc ASAN 不会因所谓的运行时错误而停止

转载 作者:行者123 更新时间:2023-12-02 08:17:28 25 4
gpt4 key购买 nike

我希望 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/

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