Merge pull request #5480 from YosysHQ/emil/libparse-fix-quoted

libparse: fix parsing and memory safety of quoted values
This commit is contained in:
Miodrag Milanović 2025-11-11 15:18:35 +01:00 committed by GitHub
commit 26b51148a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -123,7 +123,9 @@ int LibertyInputStream::peek_cold(size_t offset)
if (!extend_buffer_at_least(offset + 1))
return EOF;
}
#ifdef log_assert
log_assert(buf_pos + offset < buffer.size());
#endif
return buffer[buf_pos + offset];
}
@ -458,7 +460,6 @@ int LibertyParser::lexer_inner(std::string &str)
// if it wasn't an identifer, number of array range,
// maybe it's a string?
if (c == '"') {
f.consume(1);
size_t i = 0;
while (true) {
c = f.peek(i);
@ -469,14 +470,13 @@ int LibertyParser::lexer_inner(std::string &str)
break;
}
str.clear();
f.unget();
str.append(f.buffered_data(), f.buffered_data() + i + 1);
str.append(f.buffered_data(), f.buffered_data() + i);
// Usage in filterlib is expected to retain quotes
// but yosys expects to get unquoted
#ifdef FILTERLIB
str = "\"" + str + "\"";
#endif
f.consume(i + 2);
f.consume(i + 1);
return 'v';
}