mirror of https://github.com/YosysHQ/yosys.git
Adding width checks to frontend
This commit is contained in:
parent
ea41b196da
commit
42092cbc77
|
|
@ -31,10 +31,6 @@
|
||||||
YOSYS_NAMESPACE_BEGIN
|
YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
struct RTLILFrontendWorker {
|
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;
|
std::istream *f = nullptr;
|
||||||
RTLIL::Design *design;
|
RTLIL::Design *design;
|
||||||
bool flag_nooverwrite = false;
|
bool flag_nooverwrite = false;
|
||||||
|
|
@ -283,7 +279,7 @@ struct RTLILFrontendWorker {
|
||||||
++idx;
|
++idx;
|
||||||
|
|
||||||
std::vector<RTLIL::State> bits;
|
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());
|
error("Constant width %lld out of range before `%s`.", width, error_token());
|
||||||
bits.reserve(width);
|
bits.reserve(width);
|
||||||
int start_idx = idx;
|
int start_idx = idx;
|
||||||
|
|
@ -532,8 +528,11 @@ struct RTLILFrontendWorker {
|
||||||
wire = current_module->addWire(std::move(*id));
|
wire = current_module->addWire(std::move(*id));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (try_parse_keyword("width"))
|
if (try_parse_keyword("width")){
|
||||||
width = parse_integer();
|
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"))
|
else if (try_parse_keyword("upto"))
|
||||||
upto = true;
|
upto = true;
|
||||||
else if (try_parse_keyword("signed"))
|
else if (try_parse_keyword("signed"))
|
||||||
|
|
@ -589,8 +588,11 @@ struct RTLILFrontendWorker {
|
||||||
memory->name = std::move(*id);
|
memory->name = std::move(*id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (try_parse_keyword("width"))
|
if (try_parse_keyword("width")){
|
||||||
width = parse_integer();
|
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"))
|
else if (try_parse_keyword("size"))
|
||||||
size = parse_integer();
|
size = parse_integer();
|
||||||
else if (try_parse_keyword("offset"))
|
else if (try_parse_keyword("offset"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue