From 048446fc7412d5201bbceac234eb3c18cf31e4c5 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 20 Jun 2017 13:16:55 -0700 Subject: [PATCH] Fix cassandra ASAN use-after-free Summary: When we create a column based on the `string::c_str()`, we need to make sure that char array doesn't get deleted when calls to `string::append()` cause the string to expand. Closes https://github.com/facebook/rocksdb/pull/2470 Differential Revision: D5285049 Pulled By: ajkr fbshipit-source-id: f918dd426ff3c024e7a293dcb10448f10b6c98e8 --- utilities/merge_operators/cassandra/format_test.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utilities/merge_operators/cassandra/format_test.cc b/utilities/merge_operators/cassandra/format_test.cc index 381cf0828..2def0d003 100644 --- a/utilities/merge_operators/cassandra/format_test.cc +++ b/utilities/merge_operators/cassandra/format_test.cc @@ -45,7 +45,8 @@ TEST(ColumnTest, Column) { EXPECT_TRUE(std::memcmp(data, dest.c_str() + offset, sizeof(data)) == 0); // Verify the deserialization. - std::unique_ptr c1 = Column::Deserialize(dest.c_str(), 0); + std::string saved_dest = dest; + std::unique_ptr c1 = Column::Deserialize(saved_dest.c_str(), 0); EXPECT_EQ(c1->Index(), index); EXPECT_EQ(c1->Timestamp(), timestamp); EXPECT_EQ(c1->Size(), 14 + sizeof(data)); @@ -56,8 +57,9 @@ TEST(ColumnTest, Column) { std::memcmp(dest.c_str(), dest.c_str() + c.Size(), c.Size()) == 0); // Verify the ColumnBase::Deserialization. + saved_dest = dest; std::unique_ptr c2 = - ColumnBase::Deserialize(dest.c_str(), c.Size()); + ColumnBase::Deserialize(saved_dest.c_str(), c.Size()); c2->Serialize(&dest); EXPECT_EQ(dest.size(), 3 * c.Size()); EXPECT_TRUE( @@ -98,8 +100,9 @@ TEST(ExpiringColumnTest, ExpiringColumn) { EXPECT_EQ(Deserialize(dest.c_str(), offset), ttl); // Verify the deserialization. + std::string saved_dest = dest; std::unique_ptr c1 = - ExpiringColumn::Deserialize(dest.c_str(), 0); + ExpiringColumn::Deserialize(saved_dest.c_str(), 0); EXPECT_EQ(c1->Index(), index); EXPECT_EQ(c1->Timestamp(), timestamp); EXPECT_EQ(c1->Size(), 18 + sizeof(data)); @@ -110,8 +113,9 @@ TEST(ExpiringColumnTest, ExpiringColumn) { std::memcmp(dest.c_str(), dest.c_str() + c.Size(), c.Size()) == 0); // Verify the ColumnBase::Deserialization. + saved_dest = dest; std::unique_ptr c2 = - ColumnBase::Deserialize(dest.c_str(), c.Size()); + ColumnBase::Deserialize(saved_dest.c_str(), c.Size()); c2->Serialize(&dest); EXPECT_EQ(dest.size(), 3 * c.Size()); EXPECT_TRUE(