Add mbe expand limit and poision macro set

This commit is contained in:
Edwin Cheng 2019-04-22 15:33:55 +08:00
parent bbc5c1d24e
commit b177813f3b
5 changed files with 216 additions and 18 deletions

View file

@ -94,6 +94,13 @@ fn parse_macro(
let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?;
let tt = macro_rules.expand(&macro_arg).map_err(|err| format!("{:?}", err))?;
// Set a hard limit for the expanded tt
let count = tt.count();
if count > 65536 {
return Err(format!("Total tokens count exceed limit : count = {}", count));
}
Ok(mbe::token_tree_to_ast_item_list(&tt))
}