Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix for MacroRuleDefinition use-after-free #2676

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ class MacroRulesDefinition : public VisItem

MacroKind get_kind () const { return kind; }

std::unique_ptr<MacroRulesDefinition> clone_macro_rules_def () const
{
return std::unique_ptr<MacroRulesDefinition> (clone_item_impl ());
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
auto it = macroInvocations.find (invoc.get_macro_node_id ());
rust_assert (it == macroInvocations.end ());

macroInvocations[invoc.get_macro_node_id ()] = def;
// TODO: remove hack that converts use-after-free into memory leak
macroInvocations[invoc.get_macro_node_id ()] = def->clone_macro_rules_def ().release ();
}

bool
Expand Down
Loading