提问人:JoeManiaci 提问时间:7/22/2022 最后编辑:SneftelJoeManiaci 更新时间:8/4/2022 访问量:392
未定义行为清理器缺少添加溢出检查
Undefined Behavior Sanitizer missing addition overflow check
问:
当我使用 nm |grep '__ubsan',则返回:
U __ubsan_handle_add_overflow
U __ubsan_handle_divrem_overflow
U __ubsan_handle_dynamic_type_cache_miss
U __ubsan_handle_load_invalid_value
U __ubsan_handle_mul_overflow
U __ubsan_handle_negate_overflow
U __ubsan_handle_nonnull_arg
U __ubsan_handle_nonnull_return
U __ubsan_handle_out_of_bounds
U __ubsan_handle_shift_out_of_bounds
U __ubsan_handle_sub_overflow
U __ubsan_handle_type_mismatch
U __ubsan_handle_vla_bound_not_positive
U __ubsan_vptr_type_cache
我假设__ubsan_handle_add_overflow是检查加法溢出的仪器。在我的代码中,我添加了:
auto test = UINT_MAX;
test += 15;
但是,我没有看到与之相关的“运行时错误:”消息。
我们的代码库确实使用以下方法去除调试符号:
strip --strip-debug --strip-unneeded
我发现“--strip-unneeded”去除了与消毒剂相关的符号,因为调用“nm”是空白的。如果我只使用'strip --strip-debug',我会得到与上面相同的nm输出。我是否还需要存在调试符号才能使清理程序符号正常工作?我可以看到我的程序的内存消耗从 ~175MB 增加到 ~265MB。
我为启用 ubsan 所做的只是 -fvisibility=default 和 -fsanitize=undefined
我处于一个 ARM 嵌入式环境中,遗憾的是,它没有为我提供足够的空间来快速测试存在清理程序和调试符号来测试这一理论。我们的 x86 构建在技术上是可以运行的,我看到清理程序的运行时错误,所以也许这证明了这一点,因为它存在清理程序和调试符号?
答:
2赞
Sneftel
8/4/2022
#1
-fsanitize-undefined
启用对未定义行为的检查。但是,无符号整数溢出(正如您在此处调用的那样)并不是未定义的行为。如果要检查未签名的溢出(可能是一个坏主意),则需要传递 .如果要调用有符号溢出(即 UB),请改为对有符号整数执行加法。-fsanitize=unsigned-integer-overflow
评论