diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-22 10:39:20 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-22 10:39:20 +0100 |
commit | 76e0129a21661029dc6cdbea2412ab53efe33aa1 (patch) | |
tree | 8da626b89a277722edd445798679339234596956 /crates/ra_hir/src/ids.rs | |
parent | bbc5c1d24e1a641b134f634516828301e8cfc320 (diff) | |
parent | ad1c3b5bd605942c85e4488b0483a0f50dc60942 (diff) |
Merge #1192
1192: Add mbe expand limit and poision macro set r=maklad a=edwin0cheng
As discussed in Zulip, this PR add a token expansion limit in `parse_macro` and a "poison" macro set in `CrateDefMap` to prevent stack over flow and limit a mbe macro size.
Note:
Right now it only handle a poison macro in a single crate, such that if other crate try to call that macro, the whole process will do again until it became poisoned in that crate.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index e771a311c..c7849c995 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -94,6 +94,13 @@ fn parse_macro( | |||
94 | 94 | ||
95 | let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?; | 95 | let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?; |
96 | let tt = macro_rules.expand(¯o_arg).map_err(|err| format!("{:?}", err))?; | 96 | let tt = macro_rules.expand(¯o_arg).map_err(|err| format!("{:?}", err))?; |
97 | |||
98 | // Set a hard limit for the expanded tt | ||
99 | let count = tt.count(); | ||
100 | if count > 65536 { | ||
101 | return Err(format!("Total tokens count exceed limit : count = {}", count)); | ||
102 | } | ||
103 | |||
97 | Ok(mbe::token_tree_to_ast_item_list(&tt)) | 104 | Ok(mbe::token_tree_to_ast_item_list(&tt)) |
98 | } | 105 | } |
99 | 106 | ||