GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.02k stars 302 forks source link

Memory sanitizer reports use-of-uninitialized-value #690

Open XiangpengHao opened 2 years ago

XiangpengHao commented 2 years ago

Memory sanitizer reports use-of-uninitialized-value on this line: https://github.com/GuillaumeGomez/sysinfo/blob/master/src/linux/utils.rs#L41

Is buf.st_mode guaranteed to be initialized?

The stack trace: ``` ==2309==WARNING: MemorySanitizer: use-of-uninitialized-value error: address range table at offset 0x3b4a0 has a premature terminator entry at offset 0x3b4b0 error: address range table at offset 0x43cd0 has a premature terminator entry at offset 0x43db0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45d90 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45db0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45dd0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45df0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45e10 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45e30 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45e50 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45e70 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45e90 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45eb0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45ed0 error: address range table at offset 0x45d30 has a premature terminator entry at offset 0x45ef0 error: address range table at offset 0xdcdb0 has a premature terminator entry at offset 0xdcdc0 #0 0x558d7cc9a7ef in sysinfo::linux::utils::realpath::h9a0b820448af059b /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/sysinfo-0.23.1/src/linux/utils.rs:41:8 #1 0x558d7cb5f458 in sysinfo::linux::process::_get_process_data::hb79fc08b66500be1 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/sysinfo-0.23.1/src/linux/process.rs:418:17 #2 0x558d7cb65499 in sysinfo::linux::process::refresh_procs::_$u7b$$u7b$closure$u7d$$u7d$::h5deb1f1a7fda1dfe /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/sysinfo-0.23.1/src/linux/process.rs:511:41 #3 0x558d7cc1b170 in _$LT$rayon..iter..filter_map..FilterMapFolder$LT$C$C$P$GT$$u20$as$u20$rayon..iter..plumbing..Folder$LT$T$GT$$GT$::consume::hb6590bb80e01503f /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/filter_map.rs:123:36 #4 0x558d7cc25169 in rayon::iter::plumbing::Folder::consume_iter::h965f2de013b4ebf8 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:179:20 #5 0x558d7cc088e4 in rayon::iter::plumbing::Producer::fold_with::h88155dbe2d388939 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:110:9 #6 0x558d7cb8e877 in rayon::iter::plumbing::bridge_producer_consumer::helper::h0c855a8120f357ea /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:438:13 #7 0x558d7cb91b9f in rayon::iter::plumbing::bridge_producer_consumer::helper::_$u7b$$u7b$closure$u7d$$u7d$::h992e81adf57d8230 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:418:21 #8 0x558d7cc18f3c in rayon_core::join::join_context::call_a::_$u7b$$u7b$closure$u7d$$u7d$::h9c87b84f51776ec3 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:124:17 #9 0x558d7cb98f9a in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h66deb956b46d7b46 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #10 0x558d7cb9b1c2 in std::panicking::try::do_call::h46229e4a9c88ffb0 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #11 0x558d7cbb14e9 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x16e24e9) #12 0x558d7cb9a0de in std::panicking::try::h43fed4210903711a /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #13 0x558d7cc9fc66 in std::panic::catch_unwind::hf2fba979d3a33131 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #14 0x558d7cc79c08 in rayon_core::unwind::halt_unwinding::h9c7f83fda587ab81 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5 #15 0x558d7cc16c8b in rayon_core::join::join_context::_$u7b$$u7b$closure$u7d$$u7d$::h57fb9d5aa0515f01 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:141:24 #16 0x558d7cc2cf20 in rayon_core::registry::in_worker::h13c1e4c48c242344 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:875:13 #17 0x558d7cc1647a in rayon_core::join::join_context::h0d55c84bb87dfbcd /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:132:5 #18 0x558d7cb8e134 in rayon::iter::plumbing::bridge_producer_consumer::helper::h0c855a8120f357ea /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:416:47 #19 0x558d7cb91b9f in rayon::iter::plumbing::bridge_producer_consumer::helper::_$u7b$$u7b$closure$u7d$$u7d$::h992e81adf57d8230 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:418:21 #20 0x558d7cc18f3c in rayon_core::join::join_context::call_a::_$u7b$$u7b$closure$u7d$$u7d$::h9c87b84f51776ec3 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:124:17 #21 0x558d7cb98f9a in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h66deb956b46d7b46 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #22 0x558d7cb9b1c2 in std::panicking::try::do_call::h46229e4a9c88ffb0 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #23 0x558d7cbb14e9 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x16e24e9) #24 0x558d7cb9a0de in std::panicking::try::h43fed4210903711a /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #25 0x558d7cc9fc66 in std::panic::catch_unwind::hf2fba979d3a33131 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #26 0x558d7cc79c08 in rayon_core::unwind::halt_unwinding::h9c7f83fda587ab81 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5 #27 0x558d7cc16c8b in rayon_core::join::join_context::_$u7b$$u7b$closure$u7d$$u7d$::h57fb9d5aa0515f01 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:141:24 #28 0x558d7cc2cf20 in rayon_core::registry::in_worker::h13c1e4c48c242344 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:875:13 #29 0x558d7cc1647a in rayon_core::join::join_context::h0d55c84bb87dfbcd /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:132:5 #30 0x558d7cb8e134 in rayon::iter::plumbing::bridge_producer_consumer::helper::h0c855a8120f357ea /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:416:47 #31 0x558d7cb91b9f in rayon::iter::plumbing::bridge_producer_consumer::helper::_$u7b$$u7b$closure$u7d$$u7d$::h992e81adf57d8230 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:418:21 #32 0x558d7cc18f3c in rayon_core::join::join_context::call_a::_$u7b$$u7b$closure$u7d$$u7d$::h9c87b84f51776ec3 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:124:17 #33 0x558d7cb98f9a in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h66deb956b46d7b46 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #34 0x558d7cb9b1c2 in std::panicking::try::do_call::h46229e4a9c88ffb0 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #35 0x558d7cbb14e9 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x16e24e9) #36 0x558d7cb9a0de in std::panicking::try::h43fed4210903711a /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #37 0x558d7cc9fc66 in std::panic::catch_unwind::hf2fba979d3a33131 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #38 0x558d7cc79c08 in rayon_core::unwind::halt_unwinding::h9c7f83fda587ab81 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5 #39 0x558d7cc16c8b in rayon_core::join::join_context::_$u7b$$u7b$closure$u7d$$u7d$::h57fb9d5aa0515f01 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:141:24 #40 0x558d7cc2cf20 in rayon_core::registry::in_worker::h13c1e4c48c242344 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:875:13 #41 0x558d7cc1647a in rayon_core::join::join_context::h0d55c84bb87dfbcd /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:132:5 #42 0x558d7cb8e134 in rayon::iter::plumbing::bridge_producer_consumer::helper::h0c855a8120f357ea /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:416:47 #43 0x558d7cb91b9f in rayon::iter::plumbing::bridge_producer_consumer::helper::_$u7b$$u7b$closure$u7d$$u7d$::h992e81adf57d8230 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:418:21 #44 0x558d7cc18f3c in rayon_core::join::join_context::call_a::_$u7b$$u7b$closure$u7d$$u7d$::h9c87b84f51776ec3 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:124:17 #45 0x558d7cb98f9a in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h66deb956b46d7b46 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #46 0x558d7cb9b1c2 in std::panicking::try::do_call::h46229e4a9c88ffb0 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #47 0x558d7cbb14e9 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x16e24e9) #48 0x558d7cb9a0de in std::panicking::try::h43fed4210903711a /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #49 0x558d7cc9fc66 in std::panic::catch_unwind::hf2fba979d3a33131 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #50 0x558d7cc79c08 in rayon_core::unwind::halt_unwinding::h9c7f83fda587ab81 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5 #51 0x558d7cc16c8b in rayon_core::join::join_context::_$u7b$$u7b$closure$u7d$$u7d$::h57fb9d5aa0515f01 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:141:24 #52 0x558d7cc2cf20 in rayon_core::registry::in_worker::h13c1e4c48c242344 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:875:13 #53 0x558d7cc1647a in rayon_core::join::join_context::h0d55c84bb87dfbcd /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:132:5 #54 0x558d7cb8e134 in rayon::iter::plumbing::bridge_producer_consumer::helper::h0c855a8120f357ea /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:416:47 #55 0x558d7cb90e74 in rayon::iter::plumbing::bridge_producer_consumer::helper::_$u7b$$u7b$closure$u7d$$u7d$::h80313520e7c682b6 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:427:21 #56 0x558d7cc197ba in rayon_core::join::join_context::call_b::_$u7b$$u7b$closure$u7d$$u7d$::hb52c70f2844256f6 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:129:25 #57 0x558d7cb959b1 in _$LT$rayon_core..job..StackJob$LT$L$C$F$C$R$GT$$u20$as$u20$rayon_core..job..Job$GT$::execute::call::_$u7b$$u7b$closure$u7d$$u7d$::h86a5107d4ffe9d64 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:113:21 #58 0x558d7cb990ca in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hb6045296aae474c6 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #59 0x558d7cb9b002 in std::panicking::try::do_call::h45dc5b0f9b9d5a3d /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #60 0x558d7cbb14e9 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x16e24e9) #61 0x558d7cb9a58e in std::panicking::try::hd5a78cc7fc923162 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #62 0x558d7cc9fb26 in std::panic::catch_unwind::h8587ac4847adb521 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #63 0x558d7cc79948 in rayon_core::unwind::halt_unwinding::h10ae057f6ca74266 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5 #64 0x558d7cb94961 in _$LT$rayon_core..job..StackJob$LT$L$C$F$C$R$GT$$u20$as$u20$rayon_core..job..Job$GT$::execute::hda8b305d110907bb /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:119:38 #65 0x558d7cd455da in rayon_core::job::JobRef::execute::h0687ed1c81729960 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:59:9 #66 0x558d7cd33c5f in rayon_core::registry::WorkerThread::execute::h6e3c58ad910d3606 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:749:9 #67 0x558d7cd33254 in rayon_core::registry::WorkerThread::wait_until_cold::hd05a93868ee13c80 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:726:17 #68 0x558d7cd3299e in rayon_core::registry::WorkerThread::wait_until::hcc6d1f2dc75f9ae8 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:700:13 #69 0x558d7cd3628a in rayon_core::registry::main_loop::hff5b82046da481be /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:833:5 #70 0x558d7cd2a78c in rayon_core::registry::ThreadBuilder::run::h41226e6732750f95 /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:55:18 #71 0x558d7cd2b7c8 in _$LT$rayon_core..registry..DefaultSpawn$u20$as$u20$rayon_core..registry..ThreadSpawn$GT$::spawn::_$u7b$$u7b$closure$u7d$$u7d$::h186267ab15be506a /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:100:20 #72 0x558d7cde76ca in std::sys_common::backtrace::__rust_begin_short_backtrace::h377443eb422377cb /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:123:18 #73 0x558d7cce9b08 in std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h3d658e76d18c8e38 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:484:17 #74 0x558d7cd39186 in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h01c98aa3f9d74c63 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9 #75 0x558d7cd53901 in std::panicking::try::do_call::h9f73fd2eac9ea68c /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40 #76 0x558d7cd5e219 in __rust_try (/home/hao/coding/shumai/target/x86_64-unknown-linux-gnu/debug/deps/mod-9b63437fe4563907+0x188f219) #77 0x558d7cd530c9 in std::panicking::try::ha02d729af844242b /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19 #78 0x558d7cdc5470 in std::panic::catch_unwind::hf02b7ff653afc9ab /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14 #79 0x558d7cce7177 in std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::h0c42d7d31265844c /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:483:30 #80 0x558d7cde8909 in core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h82a1747970fe9e34 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5 #81 0x558d7d2ef88b in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h72111a1273f65988 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1694:9 #82 0x558d7d2ef6d9 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h629c4a10346c3e31 /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1694:9 #83 0x558d7d034c87 in std::sys::unix::thread::Thread::new::thread_start::h0924d84763159ede /home/hao/.rustup/toolchains/nightly-2021-12-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:108:17 #84 0x7f4a543d1926 in start_thread nptl/pthread_create.c:435:8 #85 0x7f4a544619e3 in clone misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:100 SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/hao/.cargo/registry/src/github.com-1ecc6299db9ec823/sysinfo-0.23.1/src/linux/utils.rs:41:8 in sysinfo::linux::utils::realpath::h9a0b820448af059b Exiting ==2309==WARNING: MemorySanitizer: use-of-uninitialized-value ```
GuillaumeGomez commented 2 years ago

This is surprising. From the lstat manual:

RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

I check the returned value with res < 0, so I'm following what the manual is saying on how to check that the call didn't fail. If we continue reading the manual there is this note:

Note: for performance and simplicity reasons, different fields in the stat structure may con‐ tain state information from different moments during the execution of the system call. For example, if st_mode or st_uid is changed by another process by calling chmod(2) or chown(2), stat() might return the old st_mode together with the new st_uid, or the old st_uid together with the new st_mode.

But it's not uninitialized, simply "outdated". However, even below we have:

According to POSIX.1-2001, lstat() on a symbolic link need return valid information only in the st_size field and the file type of the st_mode field of the stat structure. POSIX.1-2008 tightens the specification, requiring lstat() to return valid information in all fields except the mode bits in st_mode.

So it seems like there is definitely something wrong going on.

XiangpengHao commented 2 years ago

I checked out the latest code, but unfortunately it doesn't seem to fix the problem...

This can be reproduced by running the test_process test case

env RUSTFLAGS="-Z sanitizer=memory" cargo test -Zbuild-std --target x86_64-unknown-linux-gnu  -- test_process --exact

I looked at the st_mode and it is indeed modified by the lstat call. Maybe it's a bug deep in the memory sanitizer?

XiangpengHao commented 2 years ago

A possible workaround is to do MaybeUninit::<stat>::zeroed() instead of uninit()

The root cause might be that the libc is not properly instrumented (not compiled with -fsanitize=memory, and I don't know how) which leads to the false-positive warning from memory sanitizer.

Anyway, it's probably not a bug in this crate, but I need to figure out a way to use it with memory sanitizer...

Edit: seems that the libc is dynamically linked, which is not great...

GuillaumeGomez commented 2 years ago

When switching to zeroed, it indeed works for this test. But then we get another error I couldn't track down...

XiangpengHao commented 2 years ago

I only got doc tests failed after switching to zeroed(). The errors are likely not related to this change, it's just that the lib tests get the chance to run first and aborts on the first error encountered.

Seems that memory sanitizer doesn't play well with the doc tests, but at least the lib tests all passed