Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1462)

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 1725363005: Fix use after free in memory only backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shorter2
Patch Set: remediate Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/disk_cache/memory/mem_entry_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index ebd2f578ae578a2df3d50d7b20f2642d0d26aa4d..7f2259dc609d955b4580fb8678fbd20095b1aa9c 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -2947,6 +2947,44 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) {
// TODO(gavinp): Enable BackendEviction test for simple cache after performance
// problems are addressed. See crbug.com/588184 for more information.
+// This overly specific looking test is a regression test aimed at
+// crbug.com/589186.
+TEST_F(DiskCacheBackendTest, MemoryOnlyUseAfterFree) {
gavinp 2016/02/25 15:55:32 The rename of the test makes it way more consisten
+ SetMemoryOnlyMode();
+
+ const int kMaxSize = 200 * 1024;
+ const int kMaxEntryCount = 20;
+ const int kWriteSize = kMaxSize / kMaxEntryCount;
+
+ SetMaxSize(kMaxSize);
+ InitCache();
+
+ scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kWriteSize));
+ CacheTestFillBuffer(buffer->data(), kWriteSize, false);
+
+ // Create an entry to be our sparse entry that gets written later.
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry("first parent", &entry));
+ disk_cache::ScopedEntryPtr first_parent(entry);
+
+ // Create a ton of entries, and keep them open, to put the cache well above
+ // its eviction threshhold.
+ const int kTooManyEntriesCount = kMaxEntryCount * 2;
+ std::list<disk_cache::ScopedEntryPtr> open_entries;
+ std::string key_prefix("prefix");
+ for (int i = 0; i < kTooManyEntriesCount; ++i) {
+ ASSERT_EQ(net::OK, CreateEntry(key_prefix + base::IntToString(i), &entry));
+ EXPECT_EQ(kWriteSize,
+ WriteData(entry, 1, 0, buffer.get(), kWriteSize, false));
+ open_entries.push_back(disk_cache::ScopedEntryPtr(entry));
+ }
+ EXPECT_LT(kMaxSize, CalculateSizeOfAllEntries());
+
+ // Writing this sparse data should not crash.
+ EXPECT_EQ(1024, first_parent->WriteSparseData(32768, buffer.get(), 1024,
+ net::CompletionCallback()));
+}
+
TEST_F(DiskCacheTest, Backend_UsageStatsTimer) {
MessageLoopHelper helper;
« no previous file with comments | « no previous file | net/disk_cache/memory/mem_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698