docopt / docopt.cpp

C++11 port of docopt
Boost Software License 1.0
1.04k stars 146 forks source link

MSAN Warning on use-of-initialized-value in docopt::docopt_parse #149

Open acgetchell opened 2 years ago

acgetchell commented 2 years ago

Running my project through MSAN, which uses Docopt.cpp, gives me the following:

WARNING: MemorySanitizer: use-of-uninitialized-value
[1441]()6:     #0 0x434fdc in bcmp (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x434fdc)
[1442]()6:     #1 0x625c4a in docopt::docopt_parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >,

I think the error might be in this line:

docopt::docopt_parse(std::string const& doc,
             std::vector<std::string> const& argv,
             bool help,
             bool version,
             bool options_first)
{
    Required pattern;
    std::vector<Option> options; // <-- here
jaredgrubb commented 2 years ago

Hm, that line invokes the default C++ constructor so it can't be the issue. Does MSAN flag the actual line of code?

acgetchell commented 2 years ago

Yeah, saw that. My latest CI build showing the docopt error is here:

https://app.travis-ci.com/github/acgetchell/CDT-plusplus/jobs/564919580#L1506

But for easy reference, the text is:

Test command: /home/travis/build/acgetchell/CDT-plusplus/build/src/initialize "--s" "-n640" "-t4" "-o"
[1502]()6: Test timeout computed to be: 1500
[1503]()6: Uninitialized bytes in MemcmpInterceptorCommon at offset 0 inside [0x714000000030, 12)
[1504]()6: ==9178==WARNING: MemorySanitizer: use-of-uninitialized-value
[1505]()6:     #0 0x434fdc in bcmp (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x434fdc)
[1506]()6:     #1 0x625c4a in docopt::docopt_parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool, bool, bool) (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x625c4a)
[1507]()6:     #2 0x629422 in docopt::docopt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x629422)
[1508]()6:     #3 0x4a02cb in main /home/travis/build/acgetchell/CDT-plusplus/build/../src/initialize.cpp:51:66
[1509]()6:     #4 0x7fd79764b0b2 in __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:308:16
[1510]()6:     #5 0x424ffd in _start (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x424ffd)
[1511]()6: 
[1512]()6: SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/travis/build/acgetchell/CDT-plusplus/build/src/initialize+0x434fdc) in bcmp
[1513]()6: Exiting