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

Side by Side Diff: content/browser/renderer_host/media/audio_input_renderer_host.cc

Issue 214343006: Check shared memory size before allocating it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/media/audio_input_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/numerics/safe_math.h"
10 #include "base/process/process.h" 11 #include "base/process/process.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "content/browser/media/capture/web_contents_audio_input_stream.h" 13 #include "content/browser/media/capture/web_contents_audio_input_stream.h"
13 #include "content/browser/media/capture/web_contents_capture_util.h" 14 #include "content/browser/media/capture/web_contents_capture_util.h"
14 #include "content/browser/media/media_internals.h" 15 #include "content/browser/media/media_internals.h"
15 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 16 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
16 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 17 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
17 #include "content/browser/renderer_host/media/media_stream_manager.h" 18 #include "content/browser/renderer_host/media/media_stream_manager.h"
18 #include "media/audio/audio_manager_base.h" 19 #include "media/audio/audio_manager_base.h"
19 20
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 253
253 // Create a new AudioEntry structure. 254 // Create a new AudioEntry structure.
254 scoped_ptr<AudioEntry> entry(new AudioEntry()); 255 scoped_ptr<AudioEntry> entry(new AudioEntry());
255 256
256 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + 257 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) +
257 audio_params.GetBytesPerBuffer()); 258 audio_params.GetBytesPerBuffer());
258 entry->shared_memory_segment_count = config.shared_memory_count; 259 entry->shared_memory_segment_count = config.shared_memory_count;
259 260
260 // Create the shared memory and share it with the renderer process 261 // Create the shared memory and share it with the renderer process
261 // using a new SyncWriter object. 262 // using a new SyncWriter object.
262 if (!entry->shared_memory.CreateAndMapAnonymous( 263 base::CheckedNumeric<uint32> size = segment_size;
263 segment_size * entry->shared_memory_segment_count)) { 264 size *= entry->shared_memory_segment_count;
265 if (!size.IsValid() ||
266 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) {
264 // If creation of shared memory failed then send an error message. 267 // If creation of shared memory failed then send an error message.
265 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); 268 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED);
266 return; 269 return;
267 } 270 }
268 271
269 scoped_ptr<AudioInputSyncWriter> writer( 272 scoped_ptr<AudioInputSyncWriter> writer(
270 new AudioInputSyncWriter(&entry->shared_memory, 273 new AudioInputSyncWriter(&entry->shared_memory,
271 entry->shared_memory_segment_count)); 274 entry->shared_memory_segment_count));
272 275
273 if (!writer->Init()) { 276 if (!writer->Init()) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // TODO(hclam): Implement a faster look up method. 426 // TODO(hclam): Implement a faster look up method.
424 for (AudioEntryMap::iterator i = audio_entries_.begin(); 427 for (AudioEntryMap::iterator i = audio_entries_.begin();
425 i != audio_entries_.end(); ++i) { 428 i != audio_entries_.end(); ++i) {
426 if (controller == i->second->controller.get()) 429 if (controller == i->second->controller.get())
427 return i->second; 430 return i->second;
428 } 431 }
429 return NULL; 432 return NULL;
430 } 433 }
431 434
432 } // namespace content 435 } // namespace content
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