Skip to content

Unsoundness in pub field "console_output" #43

Description

@lwz23

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:

  1. 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
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions