mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-21 21:33:40 +00:00
opt_dff: don't emit cells until all have been visited to prevent UAF
This commit is contained in:
parent
19cdbc5a0c
commit
8c38e2081d
1 changed files with 8 additions and 3 deletions
|
@ -737,9 +737,12 @@ struct OptDffWorker
|
|||
bool run_constbits() {
|
||||
ModWalker modwalker(module->design, module);
|
||||
QuickConeSat qcsat(modwalker);
|
||||
std::vector<RTLIL::Cell*> cells_to_remove;
|
||||
|
||||
// Run as a separate sub-pass, so that we don't mutate (non-FF) cells under ModWalker.
|
||||
// Defer mutating cells by removing them/emiting new flip flops so that
|
||||
// cell references in modwalker are not invalidated
|
||||
std::vector<RTLIL::Cell*> cells_to_remove;
|
||||
std::vector<FfData> ffs_to_emit;
|
||||
|
||||
bool did_something = false;
|
||||
for (auto cell : module->selected_cells()) {
|
||||
if (!RTLIL::builtin_ff_cell_types().count(cell->type))
|
||||
|
@ -837,12 +840,14 @@ struct OptDffWorker
|
|||
}
|
||||
ff = ff.slice(keep_bits);
|
||||
ff.cell = cell;
|
||||
ff.emit();
|
||||
ffs_to_emit.emplace_back(ff);
|
||||
did_something = true;
|
||||
}
|
||||
}
|
||||
for (auto* cell : cells_to_remove)
|
||||
module->remove(cell);
|
||||
for (auto& ff : ffs_to_emit)
|
||||
ff.emit();
|
||||
return did_something;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue