From 05bbe1fdf143652ae62fcc1e121babb6ec76726b Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 3 Apr 2021 19:03:13 -0600 Subject: do not infinitely recurse ever --- src/makefile/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index e004586..c81526b 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -5,7 +5,7 @@ use std::fmt; use std::path::{Path, PathBuf}; use std::rc::Rc; -use eyre::{eyre, Result}; +use eyre::{bail, eyre, Result}; use crate::args::Args; @@ -36,6 +36,7 @@ pub struct Makefile<'a> { pub first_non_special_target: Option, args: &'a Args, // TODO borrow warnings from Python version + fucking_bullshit_recursion_stack: RefCell>, } impl<'a> Makefile<'a> { @@ -73,6 +74,7 @@ impl<'a> Makefile<'a> { targets: RefCell::new(targets), first_non_special_target, args, + fucking_bullshit_recursion_stack: RefCell::new(Vec::new()), } } @@ -101,6 +103,16 @@ impl<'a> Makefile<'a> { } pub fn get_target(&self, name: &str) -> Result>> { + if self + .fucking_bullshit_recursion_stack + .borrow() + .contains(&name.to_owned()) + { + bail!("no infinite recursion allowed"); + } + self.fucking_bullshit_recursion_stack + .borrow_mut() + .push(name.to_owned()); // TODO implement .POSIX let follow_gnu = cfg!(feature = "full"); @@ -206,6 +218,8 @@ impl<'a> Makefile<'a> { .insert(new_target.name.clone(), Rc::new(RefCell::new(new_target))); } + self.fucking_bullshit_recursion_stack.borrow_mut().pop(); + let targets = self.targets.borrow(); Ok(Rc::clone( targets -- cgit v1.2.3