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

Side by Side Diff: core/cross/buffer.cc

Issue 194059: Check for value overlow in buffer.cc (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: Created 11 years, 3 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 | « no previous file | 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 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 if (num_elements > MAX_LARGE_INDEX) { 154 if (num_elements > MAX_LARGE_INDEX) {
155 O3D_ERROR(service_locator()) 155 O3D_ERROR(service_locator())
156 << "The maximum number of elements in a buffer is " << MAX_LARGE_INDEX 156 << "The maximum number of elements in a buffer is " << MAX_LARGE_INDEX
157 << "."; 157 << ".";
158 return false; 158 return false;
159 } 159 }
160 160
161 size_t size_in_bytes = num_elements * stride_; 161 size_t size_in_bytes = num_elements * stride_;
162 // Check for size_t overflow.
163 if (size_in_bytes / stride_ != num_elements) {
164 O3D_ERROR(service_locator())
165 << "Attempt to allocate too many elements for the current set of "
166 << "fields on buffer.";
167 return false;
168 }
162 169
163 if (size_in_bytes == 0) { 170 if (size_in_bytes == 0) {
164 O3D_ERROR(service_locator()) 171 O3D_ERROR(service_locator())
165 << "Attempt to allocate zero bytes for Buffer '" << name() << "'"; 172 << "Attempt to allocate zero bytes for Buffer '" << name() << "'";
166 return false; 173 return false;
167 } 174 }
168 175
169 bool success = true; 176 bool success = true;
170 if (!ConcreteAllocate(size_in_bytes)) { 177 if (!ConcreteAllocate(size_in_bytes)) {
171 num_elements = 0; 178 num_elements = 0;
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 locked_ = buffer_->Lock(access_mode, &data_); 604 locked_ = buffer_->Lock(access_mode, &data_);
598 if (!locked_) { 605 if (!locked_) {
599 O3D_ERROR(buffer_->service_locator()) 606 O3D_ERROR(buffer_->service_locator())
600 << "Unable to lock buffer '" << buffer_->name() << "'"; 607 << "Unable to lock buffer '" << buffer_->name() << "'";
601 } 608 }
602 } 609 }
603 return data_; 610 return data_;
604 } 611 }
605 612
606 } // namespace o3d 613 } // namespace o3d
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698