Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
pub struct FuzzVm<'a, FUZZER: Fuzzer> {
.........................
/// Data written to the console
pub console_output: Vec<u8>,
.............................
}
impl<'a, FUZZER: Fuzzer> FuzzVm<'a, FUZZER> {
........................
pub fn get_kasan_crash_path(&mut self) -> Option<String> {
/// Maximum directory name length for a KASAN crash
const MAX_PATH_LEN: usize = 164;
let console_output = unsafe { std::str::from_utf8_unchecked(&self.console_output) };
..........................
}
Considering that pub mod fuzzvm,console_output is a pub field, and get_kasan_crash_path is also a pub function. I assume that users can directly call this function and control console_output field. This potential situation could result in let console_output = unsafe { std::str::from_utf8_unchecked(&self.console_output) }; being read a invalid UTF8 data, and it will trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.
I suggest Several possible fixes:
- If there is no external usage for
console_output or get_kasan_crash_path, they should not marked as pub, at least its console_output should not marked as pub
- mark those
from_utf8_unchecked methods operating on self.console_output as unsafe and proper doc to let users know that they should provide valid UTF8 data.
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
Considering that
pub mod fuzzvm,console_outputis apubfield, andget_kasan_crash_pathis also a pub function. I assume that users can directly call this function and controlconsole_outputfield. This potential situation could result inlet console_output = unsafe { std::str::from_utf8_unchecked(&self.console_output) };being read a invalid UTF8 data, and it will trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.I suggest Several possible fixes:
console_outputorget_kasan_crash_path, they should not marked aspub, at least itsconsole_outputshould not marked aspubfrom_utf8_uncheckedmethods operating onself.console_outputas unsafe and proper doc to let users know that they should provide valid UTF8 data.