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

Side by Side Diff: ppapi/tests/test_file_io.cc

Issue 7655009: Adding guards against heap overflow in PPB_FileIO::Read (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
« no previous file with comments | « base/file_util_proxy.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 "ppapi/tests/test_file_io.h" 5 #include "ppapi/tests/test_file_io.h"
6 6
7 #include <stdio.h>
8 #include <string.h> 7 #include <string.h>
9 8
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
11 #include "ppapi/c/dev/ppb_testing_dev.h" 10 #include "ppapi/c/dev/ppb_testing_dev.h"
12 #include "ppapi/c/pp_errors.h" 11 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/ppb_file_io.h" 12 #include "ppapi/c/ppb_file_io.h"
14 #include "ppapi/c/trusted/ppb_file_io_trusted.h" 13 #include "ppapi/c/trusted/ppb_file_io_trusted.h"
15 #include "ppapi/cpp/file_io.h" 14 #include "ppapi/cpp/file_io.h"
16 #include "ppapi/cpp/file_ref.h" 15 #include "ppapi/cpp/file_ref.h"
17 #include "ppapi/cpp/file_system.h" 16 #include "ppapi/cpp/file_system.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (rv == PP_OK_COMPLETIONPENDING) 249 if (rv == PP_OK_COMPLETIONPENDING)
251 rv = callback.WaitForResult(); 250 rv = callback.WaitForResult();
252 if (rv != PP_OK) 251 if (rv != PP_OK)
253 return ReportError("FileIO::Open", rv); 252 return ReportError("FileIO::Open", rv);
254 253
255 // Write something to the file. 254 // Write something to the file.
256 rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, "test_test"); 255 rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, "test_test");
257 if (rv != PP_OK) 256 if (rv != PP_OK)
258 return ReportError("FileIO::Write", rv); 257 return ReportError("FileIO::Write", rv);
259 258
259 // Check for failing read operation.
260 char buf[256];
261 rv = file_io.Read(0, buf, -1, // negative number of bytes to read
262 callback);
263 if (rv == PP_OK_COMPLETIONPENDING)
264 rv = callback.WaitForResult();
265 if (rv != PP_ERROR_FAILED)
266 return ReportError("FileIO::Read", rv);
267
260 // Read the entire file. 268 // Read the entire file.
261 std::string read_buffer; 269 std::string read_buffer;
262 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 0, &read_buffer); 270 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 0, &read_buffer);
263 if (rv != PP_OK) 271 if (rv != PP_OK)
264 return ReportError("FileIO::Read", rv); 272 return ReportError("FileIO::Read", rv);
265 if (read_buffer != "test_test") 273 if (read_buffer != "test_test")
266 return ReportMismatch("FileIO::Read", read_buffer, "test_test"); 274 return ReportMismatch("FileIO::Read", read_buffer, "test_test");
267 275
268 // Truncate the file. 276 // Truncate the file.
269 rv = file_io.SetLength(4, callback); 277 rv = file_io.SetLength(4, callback);
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 rv = callback.WaitForResult(); 1091 rv = callback.WaitForResult();
1084 if ((invalid_combination && rv == PP_OK) || 1092 if ((invalid_combination && rv == PP_OK) ||
1085 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) { 1093 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) {
1086 return ReportOpenError(open_flags); 1094 return ReportOpenError(open_flags);
1087 } 1095 }
1088 1096
1089 return std::string(); 1097 return std::string();
1090 } 1098 }
1091 1099
1092 // TODO(viettrungluu): Test Close(). crbug.com/69457 1100 // TODO(viettrungluu): Test Close(). crbug.com/69457
OLDNEW
« no previous file with comments | « base/file_util_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698