mirror of
https://github.com/nushell/nushell.git
synced 2024-12-02 05:13:56 +01:00
bc7736bc99
# Description This PR adds a fuzzer for the nu-path and the nu-parser crate. Now you can go to `crates/nu-path/fuzz`/`crates/nu-parser/fuzz` and run `cargo fuzz` to find crashes. https://github.com/nushell/nushell/issues/10365 and #9417 was found by this --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
26 lines
820 B
Rust
26 lines
820 B
Rust
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
use nu_path::{expand_path_with, expand_tilde, expand_to_real_path, trim_trailing_slash};
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
if let Ok(s) = std::str::from_utf8(data) {
|
|
let path = std::path::Path::new(s);
|
|
|
|
// Fuzzing expand_to_real_path function
|
|
let _ = expand_to_real_path(path);
|
|
|
|
// Fuzzing trim_trailing_slash function
|
|
let _ = trim_trailing_slash(s);
|
|
|
|
// Fuzzing expand_tilde function
|
|
let _ = expand_tilde(path);
|
|
|
|
// Fuzzing expand_path_with function
|
|
// Here, we're assuming a second path for the "relative to" aspect.
|
|
// For simplicity, we're just using the current directory.
|
|
let current_dir = std::path::Path::new(".");
|
|
let _ = expand_path_with(path, ¤t_dir);
|
|
}
|
|
});
|