mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-14 11:15:40 +00:00
Adding width checks to frontend
This commit is contained in:
parent
ea41b196da
commit
42092cbc77
1 changed files with 9 additions and 7 deletions
|
|
@ -31,10 +31,6 @@
|
|||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
struct RTLILFrontendWorker {
|
||||
// Forbid constants of more than 1 Gb.
|
||||
// This will help us not explode on malicious RTLIL.
|
||||
static constexpr int MAX_CONST_WIDTH = 1024 * 1024 * 1024;
|
||||
|
||||
std::istream *f = nullptr;
|
||||
RTLIL::Design *design;
|
||||
bool flag_nooverwrite = false;
|
||||
|
|
@ -283,7 +279,7 @@ struct RTLILFrontendWorker {
|
|||
++idx;
|
||||
|
||||
std::vector<RTLIL::State> bits;
|
||||
if (width > MAX_CONST_WIDTH)
|
||||
if (width >= RTLIL::WIDTH_LIMIT)
|
||||
error("Constant width %lld out of range before `%s`.", width, error_token());
|
||||
bits.reserve(width);
|
||||
int start_idx = idx;
|
||||
|
|
@ -532,8 +528,11 @@ struct RTLILFrontendWorker {
|
|||
wire = current_module->addWire(std::move(*id));
|
||||
break;
|
||||
}
|
||||
if (try_parse_keyword("width"))
|
||||
if (try_parse_keyword("width")){
|
||||
width = parse_integer();
|
||||
if (width >= RTLIL::WIDTH_LIMIT)
|
||||
error("Wire width %lld out of range before `%s`.", width, error_token());
|
||||
}
|
||||
else if (try_parse_keyword("upto"))
|
||||
upto = true;
|
||||
else if (try_parse_keyword("signed"))
|
||||
|
|
@ -589,8 +588,11 @@ struct RTLILFrontendWorker {
|
|||
memory->name = std::move(*id);
|
||||
break;
|
||||
}
|
||||
if (try_parse_keyword("width"))
|
||||
if (try_parse_keyword("width")){
|
||||
width = parse_integer();
|
||||
if (width >= RTLIL::WIDTH_LIMIT)
|
||||
error("Memory width %lld out of range before `%s`.", width, error_token());
|
||||
}
|
||||
else if (try_parse_keyword("size"))
|
||||
size = parse_integer();
|
||||
else if (try_parse_keyword("offset"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue