mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 18:59:06 +02:00
Fuzz more realistically with keyword const eval (#15036)
# Description
The parsing logic for several of our keywords is conditional on the
particular commands for those keywords being in scope:
942030199d/crates/nu-parser/src/parse_keywords.rs (L272-L279)
Thus the following involved parsing logic was not fuzzed by the existing
`parse` fuzz target so far.
This adds an additional fuzz target `parse_with_keywords` that loads the
commands from `nu-cmd-lang`. Those are primarily the keyword
implementations, thus the relevant code paths in the parser that depend
on those `DeclId`s and the potential const eval of `if` etc. get
unlocked.
The existing `parse` target is preserved if you have concerns about the
fuzzing breaking containment in some form due to those commands.
# Tests + Formatting
Found https://github.com/nushell/nushell/issues/14972 with this target
This commit is contained in:
committed by
GitHub
parent
17246db38b
commit
55c7246830
14
crates/nu-parser/fuzz/fuzz_targets/parse_with_keywords.rs
Normal file
14
crates/nu-parser/fuzz/fuzz_targets/parse_with_keywords.rs
Normal file
@ -0,0 +1,14 @@
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use nu_cmd_lang::create_default_context;
|
||||
use nu_parser::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let engine_state = create_default_context();
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
|
||||
let _block = parse(&mut working_set, None, &data, true);
|
||||
});
|
Reference in New Issue
Block a user