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

Side by Side Diff: webkit/plugins/ppapi/quota_file_io_unittest.cc

Issue 7651002: Adding checks to guard against buffer overruns in QuotaFileIO::Write and base::FileUtilProxy::Write (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« ppapi/c/ppb_file_io.h ('K') | « webkit/plugins/ppapi/quota_file_io.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <deque> 5 #include <deque>
6 #include <limits>
7 #include <string>
6 8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/memory/scoped_callback_factory.h" 10 #include "base/memory/scoped_callback_factory.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/platform_file.h" 12 #include "base/platform_file.h"
11 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
12 #include "base/task.h" 14 #include "base/task.h"
13 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" 15 #include "webkit/plugins/ppapi/mock_plugin_delegate.h"
14 #include "webkit/plugins/ppapi/ppapi_unittest.h" 16 #include "webkit/plugins/ppapi/ppapi_unittest.h"
15 #include "webkit/plugins/ppapi/quota_file_io.h" 17 #include "webkit/plugins/ppapi/quota_file_io.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::ClosePlatformFile(file_); 110 base::ClosePlatformFile(file_);
109 PpapiUnittest::TearDown(); 111 PpapiUnittest::TearDown();
110 } 112 }
111 113
112 protected: 114 protected:
113 virtual MockPluginDelegate* NewPluginDelegate() OVERRIDE { 115 virtual MockPluginDelegate* NewPluginDelegate() OVERRIDE {
114 return static_cast<MockPluginDelegate*>(new QuotaMockPluginDelegate); 116 return static_cast<MockPluginDelegate*>(new QuotaMockPluginDelegate);
115 } 117 }
116 118
117 void WriteTestBody(bool will_operation) { 119 void WriteTestBody(bool will_operation) {
120 // Attempt to write zero bytes.
121 EXPECT_FALSE(quota_file_io_->Write(0, "data", 0,
122 callback_factory_.NewCallback(
123 &QuotaFileIOTest::DidWrite)));
124 // Attempt to write negative number of bytes.
125 EXPECT_FALSE(quota_file_io_->Write(0, "data",
126 std::numeric_limits<int32_t>::min(),
127 callback_factory_.NewCallback(
128 &QuotaFileIOTest::DidWrite)));
129
118 quota_plugin_delegate()->set_available_space(100); 130 quota_plugin_delegate()->set_available_space(100);
119 std::string read_buffer; 131 std::string read_buffer;
120 132
121 // Write 8 bytes at offset 0 (-> length=8). 133 // Write 8 bytes at offset 0 (-> length=8).
122 std::string data("12345678"); 134 std::string data("12345678");
123 Write(0, data, will_operation); 135 Write(0, data, will_operation);
124 MessageLoop::current()->RunAllPending(); 136 MessageLoop::current()->RunAllPending();
125 ASSERT_EQ(1U, num_results()); 137 ASSERT_EQ(1U, num_results());
126 EXPECT_EQ(static_cast<int>(data.size()), bytes_written().front()); 138 EXPECT_EQ(static_cast<int>(data.size()), bytes_written().front());
127 EXPECT_EQ(base::PLATFORM_FILE_OK, status().front()); 139 EXPECT_EQ(base::PLATFORM_FILE_OK, status().front());
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 pop_result(); 491 pop_result();
480 492
481 EXPECT_EQ(22 - 15, quota_plugin_delegate()->available_space()); 493 EXPECT_EQ(22 - 15, quota_plugin_delegate()->available_space());
482 EXPECT_EQ(15, GetPlatformFileSize()); 494 EXPECT_EQ(15, GetPlatformFileSize());
483 ReadPlatformFile(&read_buffer); 495 ReadPlatformFile(&read_buffer);
484 EXPECT_EQ("123355559012345", read_buffer); 496 EXPECT_EQ("123355559012345", read_buffer);
485 } 497 }
486 498
487 } // namespace ppapi 499 } // namespace ppapi
488 } // namespace webkit 500 } // namespace webkit
OLDNEW
« ppapi/c/ppb_file_io.h ('K') | « webkit/plugins/ppapi/quota_file_io.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698