mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 15:11:52 +02:00
Limit recursion to avoid stack overflow (#7657)
Add recursion limit to `def` and `block`. Summary of this PR , it will detect if `def` call itself or not . Then execute by using `stack` which I think best choice to use with this design and core as it is available in all crates and mutable and calculate the recursion limit on calling `def`. Set 50 as recursion limit on `Config`. Add some tests too . Fixes #5899 Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
This commit is contained in:
committed by
GitHub
parent
9bc4e6794d
commit
00469de93e
@ -34,6 +34,7 @@ pub struct Stack {
|
||||
pub env_hidden: HashMap<String, HashSet<String>>,
|
||||
/// List of active overlays
|
||||
pub active_overlays: Vec<String>,
|
||||
pub recursion_count: Box<u64>,
|
||||
}
|
||||
|
||||
impl Stack {
|
||||
@ -43,6 +44,7 @@ impl Stack {
|
||||
env_vars: vec![],
|
||||
env_hidden: HashMap::new(),
|
||||
active_overlays: vec![DEFAULT_OVERLAY_NAME.to_string()],
|
||||
recursion_count: Box::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,6 +125,7 @@ impl Stack {
|
||||
env_vars,
|
||||
env_hidden: HashMap::new(),
|
||||
active_overlays: self.active_overlays.clone(),
|
||||
recursion_count: self.recursion_count.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,6 +150,7 @@ impl Stack {
|
||||
env_vars,
|
||||
env_hidden: HashMap::new(),
|
||||
active_overlays: self.active_overlays.clone(),
|
||||
recursion_count: self.recursion_count.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user