diff options
author | Cliff L. Biffle <code@cliffle.com> | 2017-05-09 08:06:43 -0700 |
---|---|---|
committer | Cliff L. Biffle <code@cliffle.com> | 2017-05-09 08:06:43 -0700 |
commit | e787fa2d3013365f20a062577254276263482aae (patch) | |
tree | 4ee5e8459b492b43d700d78a0a2cb9688427eb48 /icetime | |
parent | 0f64fdf573f098a98c178bb1b64571b577d5aa33 (diff) | |
download | icestorm-e787fa2d3013365f20a062577254276263482aae.tar.gz icestorm-e787fa2d3013365f20a062577254276263482aae.tar.bz2 icestorm-e787fa2d3013365f20a062577254276263482aae.zip |
icetime: never silently truncate asc file lines
icetime was reading the asc configuration file using a 128-byte line
buffer -- which is usually fine, but can cause it to truncate the names
of nets given in .sym lines if those names are very, very long. The way
fgets was being used meant this went undetected.
Long net names like this can arise in deeply hierarchical designs,
particularly if there's a code generator involved.
This change:
1. Increases the buffer size to 64kiB.
2. Adds a truncation check that causes icetime to fail.
A more robust solution would manage the line buffer on the heap, since
the symbol gets copied into a std::string anyway, but this is a
workaround for now.
Diffstat (limited to 'icetime')
-rw-r--r-- | icetime/icetime.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/icetime/icetime.cc b/icetime/icetime.cc index cf6aa5b..58ae3bf 100644 --- a/icetime/icetime.cc +++ b/icetime/icetime.cc @@ -208,11 +208,19 @@ void read_pcf(const char *filename) void read_config() { - char buffer[128]; + constexpr size_t line_buf_size = 65536; + char buffer[line_buf_size]; int tile_x, tile_y, line_nr = -1; - while (fgets(buffer, 128, fin)) + while (fgets(buffer, line_buf_size, fin)) { + if (buffer[strlen(buffer) - 1] != '\n') + { + fprintf(stderr, "Input file contains very long lines.\n"); + fprintf(stderr, "icetime cannot process it.\n"); + exit(1); + } + if (buffer[0] == '.') { line_nr = -1; |