Skip to content

Commit 26b5114

Browse files
authored
Merge pull request #5480 from YosysHQ/emil/libparse-fix-quoted
libparse: fix parsing and memory safety of quoted values
2 parents 596ad37 + 967e91a commit 26b5114

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

passes/techmap/libparse.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ int LibertyInputStream::peek_cold(size_t offset)
123123
if (!extend_buffer_at_least(offset + 1))
124124
return EOF;
125125
}
126-
126+
#ifdef log_assert
127+
log_assert(buf_pos + offset < buffer.size());
128+
#endif
127129
return buffer[buf_pos + offset];
128130
}
129131

@@ -458,7 +460,6 @@ int LibertyParser::lexer_inner(std::string &str)
458460
// if it wasn't an identifer, number of array range,
459461
// maybe it's a string?
460462
if (c == '"') {
461-
f.consume(1);
462463
size_t i = 0;
463464
while (true) {
464465
c = f.peek(i);
@@ -469,14 +470,13 @@ int LibertyParser::lexer_inner(std::string &str)
469470
break;
470471
}
471472
str.clear();
472-
f.unget();
473-
str.append(f.buffered_data(), f.buffered_data() + i + 1);
473+
str.append(f.buffered_data(), f.buffered_data() + i);
474474
// Usage in filterlib is expected to retain quotes
475475
// but yosys expects to get unquoted
476476
#ifdef FILTERLIB
477477
str = "\"" + str + "\"";
478478
#endif
479-
f.consume(i + 2);
479+
f.consume(i + 1);
480480
return 'v';
481481
}
482482

0 commit comments

Comments
 (0)