2

我的应用程序正在使用boost::program_options,它在从异常生成错误消息时触发了 AddressSanitizer“堆栈缓冲区溢出”。

我不担心 boost 错误 - 该功能有效,这只是在非生产应用程序的命令行解析部分中。但是我想禁止 AddressSanitizer 消息。

ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffe6ce7070 at pc 0x0000007406cd bp 0x7fffe6ce6fe0 sp 0x7fffe6ce6fd8
READ of size 8 at 0x7fffe6ce7070 thread T0
    #0 0x7406cc in std::_Head_base<0ul, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, false>::_M_head(std::_Head_base<0ul, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, false>&) /frc/toolchain6/include/c++/5.3.0/tuple:142
    #1 0x7406cc in _M_create_node /frc/toolchain6/include/c++/5.3.0/tuple:347
    #2 0x7403fd in std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>&&, std::tuple<>&&) /frc/toolchain6/include/c++/5.3.0/bits/stl_tree.h:2170
    #3 0xd5eff8 in boost::program_options::error_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const (/home/joe/myapp_workspace/myapp/myapp-debug+0xd5eff8)
    #4 0xd5c0dd in boost::program_options::error_with_option_name::what() const (/home/joe/myapp_workspace/myapp/myapp-debug+0xd5c0dd)
    #5 0x58addf in main /home/joe/myapp_workspace/myapp/main.cpp:62
    #6 0x7fd7e056176c in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #7 0x436aa0  (/home/joe/myapp_workspace/myapp/myapp-debug+0x436aa0)

我尝试过使用 ASAN_OPTIONS 抑制文件方法,但这似乎只支持非常短的错误类型列表(例如“vptr_check”和“leak”)。

4

1 回答 1

2

我认为没有一种简单的方法可以抑制这个错误——Asan 的 Clang 版本具有黑名单机制,但它对上下文不敏感,因此您必须在所有std::string非常不受欢迎的用法中禁用内存检查。

一种选择是使用-fsanitize-recover=address编译器标志并添加halt_on_error=0到您的ASAN_OPTIONS环境变量中(有关详细信息,请参阅wiki并注意仅支持相对较新的 GCC 和 Clang 的恢复)。这将在第一个错误后继续执行。然后,您将能够查看完整的 Asan 报告并选择您感兴趣的内容。

于 2016-10-28T12:32:10.897 回答