Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use-of-uninitialized-value with String usage #54365

Closed
antoyo opened this issue Sep 19, 2018 · 6 comments
Closed

use-of-uninitialized-value with String usage #54365

antoyo opened this issue Sep 19, 2018 · 6 comments
Labels
A-sanitizers Area: Sanitizers for correctness and code quality

Comments

@antoyo
Copy link
Contributor

antoyo commented Sep 19, 2018

The following code:

fn main() {
    let _string = "foobar".to_string();
}

causes the following error when compiled with RUSTFLAG="-Z sanitizer=memory":

==8391==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55fba33e0fb4 in _$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..DerefMut$GT$::deref_mut::h3a0e58767aa3b236 /checkout/src/liballoc/vec.rs:1762:12
    #1 0x55fba33e1122 in _$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..index..IndexMut$LT$I$GT$$GT$::index_mut::hb2387792320c3e0a /checkout/src/liballoc/vec.rs:1740:33
    #2 0x55fba33e0ea8 in _$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::hc074c17d1983d45e /checkout/src/liballoc/vec.rs:2186:36
    #3 0x55fba33e13cb in core::ptr::drop_in_place::hb4be232c9bbba2a8 /checkout/src/libcore/ptr.rs:59
    #4 0x55fba33e14a9 in core::ptr::drop_in_place::hbc9ae6e2a77742fc /checkout/src/libcore/ptr.rs:59
    #5 0x55fba33e0b53 in rust_test::main::hbdb4645a96927ff3 /path/to/rust-test/src/main.rs:3
    #6 0x55fba33dfc25 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hdbb070f7f9cb20f3 /checkout/src/libstd/rt.rs:74:33
    #7 0x55fba3444a72 in std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::hf9ed89fe31802c27 /checkout/src/libstd/rt.rs:59:12
    #8 0x55fba3444a72 in _ZN3std9panicking3try7do_call17h34f710c6c7436ab4E.llvm.17120388486034956999 /checkout/src/libstd/panicking.rs:310
    #9 0x55fba3452b59 in __rust_maybe_catch_panic /checkout/src/libpanic_unwind/lib.rs:102:7
    #10 0x55fba343b2f5 in std::panicking::try::hde1f350b7d320158 /checkout/src/libstd/panicking.rs:289:12
    #11 0x55fba343b2f5 in std::panic::catch_unwind::h36d4846b7bd01358 /checkout/src/libstd/panic.rs:392
    #12 0x55fba343b2f5 in std::rt::lang_start_internal::hb067be5f5219a9c5 /checkout/src/libstd/rt.rs:58
    #13 0x55fba33dfb4e in std::rt::lang_start::h0fc74e8614dd1c16 /checkout/src/libstd/rt.rs:74:4
    #14 0x55fba33e0bc1 in main (/path/to/rust-test/target/debug/rust-test+0xabc1)
    #15 0x7f12e6327222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
    #16 0x55fba33df40d in _start (/path/to/rust-test/target/debug/rust-test+0x940d)

Other string usages like calling push() causes a similar error.
Thanks to fix the issue.

@alexcrichton
Copy link
Member

This is highly likely to be a valgrind false positive, we have had many of those historically

@malikolivier
Copy link

malikolivier commented Sep 20, 2018

I cannot say if it's related. I have the same issue with File::open.

use std::fs::File;

fn main() {
    let _ = File::open("foo");
}
$ RUSTFLAGS="-Z sanitizer=memory" cargo +nightly run --target x86_64-unknown-linux-gnu
   Compiling main v0.1.2 (/home/malik/workspace/opensource/fitrs)
    Finished dev [unoptimized + debuginfo] target(s) in 1.01s                                                                                                                             
     Running `target/x86_64-unknown-linux-gnu/debug/main`
==7765==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x555e786e526e  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0xb26e)
    #1 0x555e786e3d63  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x9d63)
    #2 0x555e786e4fb5  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0xafb5)
    #3 0x555e7874a192  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x70192)
    #4 0x555e78756c19  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x7cc19)
    #5 0x555e78741235  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x67235)
    #6 0x555e786e4ede  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0xaede)
    #7 0x555e786e3dd1  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x9dd1)
    #8 0x7f9098f9fb96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #9 0x555e786e37f9  (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0x97f9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/malik/workspace/opensource/fitrs/target/x86_64-unknown-linux-gnu/debug/main+0xb26e) 
Exiting
  • rustc version: rustc 1.30.0-nightly (20dc0c507 2018-09-19)
  • OS: Ubuntu 18.04

These may be the manifestations of some limitations of the memory sanitizer (a.k.a false positives).
Is there any documentation about the proper uses of sanitizers when dealing with false positives?

Similarly to https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions, is there any way to set up a black list for the memory sanitizers in function calls to std (or any other crates)?

@antoyo
Copy link
Contributor Author

antoyo commented Sep 25, 2018

Same with std::thread::spawn(|| { });.

@antoyo
Copy link
Contributor Author

antoyo commented Oct 4, 2018

This might be a duplicate of #39610.

@jonas-schievink jonas-schievink added the A-sanitizers Area: Sanitizers for correctness and code quality label Jan 27, 2019
@alex
Copy link
Member

alex commented Apr 2, 2019

MSAN always requires you to have all code (including libstd, and libc) compiled with MSAN. If all you're doing is compiling your code with it, you'll get tons of false positives. Unless there's more going on here, I think this can be closed.

@tmiasko
Copy link
Contributor

tmiasko commented Aug 29, 2020

As mentioned earlier, MemorySanitizer requires all code to be instrumented. The documentation describes how to instrument the Rust standard library using cargo build-std functionality.

This should be closed along with #49893.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sanitizers Area: Sanitizers for correctness and code quality
Projects
None yet
Development

No branches or pull requests

7 participants