我的应用程序正在使用boost::program_options,它正在触发AddressSanitizer“stack-buffer-overflow”,同时从异常生成错误消息。

我不担心增强错误-该功能可以正常工作,而这只是在非生产应用程序的命令行解析部分中。但是,我想隐藏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”)。

最佳答案

我认为没有简单的方法可以解决此错误-Asan的Clang版本具有黑名单机制,但是它对上下文不敏感,因此您必须在std::string的所有用法中禁用内存检查,这是非常不希望的。

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

关于c++ - 我如何抑制gcc中来自AddressSanitizer的堆栈缓冲区溢出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36865774/

10-11 16:54