Memory sanitizer false positive on centos 7 but not on other platform

407 Views Asked by At

my test code is the following:

#include <string>
#include <iostream>


int main()
{
  std::string mylongstring("This is a test string");
  std::cout << mylongstring << std::endl;
}

and I compile with the latest clang, using a GCC 7.2 toolchain.
clang++ -fsanitize=memory msan.cp

This is essentially a reproducer for a problem that I see trying to integrate the memory sanitizer in a big software stack running on a centos 7 server.

And this little example code produces the following error:

Uninitialized bytes in __interceptor_fwrite at offset 0 inside [0x702000000000, 21)
==34234==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2acebbd9f3 in std::basic_streambuf<char, std::char_traits<char> >::sputn(char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:451
    #1 0x7f2acebbd9f3 in void std::__ostream_write<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:50
    #2 0x7f2acebbd9f3 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:101
    #3 0x4ab06d in main (/home/*----*/intelhackathon/a.out+0x4ab06d)
    #4 0x7f2acdbcdc04 in __libc_start_main (/lib64/libc.so.6+0x21c04)
    #5 0x41b323 in _start (/home/*----*/intelhackathon/a.out+0x41b323)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:451 in std::basic_streambuf<char, std::char_traits<char> >::sputn(char const*, long)
Exiting

However, this only happens on the centos server, when trying this on my local arch linux system I don't see any errors and it works as expected.

Server details:
glibc : 2.17-196.el7
uname -a:
Linux servername 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I'm mostly out of ideas so would be happy for any help or even suggestions of what I could try.

Thanks! :)

0

There are 0 best solutions below