Fix heap-use-after-free when writing section index

When writing the section index block, an additional entry was added
to the index, potentially reallocating the vector containing the
index. However, we previously took the address of the vector data
in order to write the index, so that address is now invalid.

Fix is by not adding the extra entry to the index.
This commit is contained in:
Marcus Holland-Moritz 2022-10-21 11:06:28 +02:00
parent 59b87cdd9f
commit bf2064f650

View File

@ -383,7 +383,9 @@ void filesystem_writer_<LoggerPolicy>::write(folly::ByteRange range) {
template <typename LoggerPolicy>
void filesystem_writer_<LoggerPolicy>::write(fsblock const& fsb) {
push_section_index(fsb.type());
if (fsb.type() != section_type::SECTION_INDEX) {
push_section_index(fsb.type());
}
write(fsb.header());
write(fsb.data());