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

Side by Side Diff: ipc/ipc_message.cc

Issue 717793005: Fix signed integer overflow in GetRefNumUpper24. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 "ipc/ipc_message.h" 5 #include "ipc/ipc_message.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 #if defined(OS_POSIX) 11 #if defined(OS_POSIX)
12 #include "base/file_descriptor_posix.h" 12 #include "base/file_descriptor_posix.h"
13 #include "ipc/file_descriptor_set_posix.h" 13 #include "ipc/file_descriptor_set_posix.h"
14 #endif 14 #endif
15 15
16 namespace { 16 namespace {
17 17
18 base::StaticAtomicSequenceNumber g_ref_num; 18 base::StaticAtomicSequenceNumber g_ref_num;
19 19
20 // Create a reference number for identifying IPC messages in traces. The return 20 // Create a reference number for identifying IPC messages in traces. The return
21 // values has the reference number stored in the upper 24 bits, leaving the low 21 // values has the reference number stored in the upper 24 bits, leaving the low
22 // 8 bits set to 0 for use as flags. 22 // 8 bits set to 0 for use as flags.
23 inline uint32 GetRefNumUpper24() { 23 inline uint32 GetRefNumUpper24() {
24 base::debug::TraceLog* trace_log = base::debug::TraceLog::GetInstance(); 24 base::debug::TraceLog* trace_log = base::debug::TraceLog::GetInstance();
25 int32 pid = trace_log ? trace_log->process_id() : 0; 25 uint32 pid = trace_log ? trace_log->process_id() : 0;
26 int32 count = g_ref_num.GetNext(); 26 uint32 count = g_ref_num.GetNext();
27 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the 27 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the
28 // Process ID. With the current trace event buffer cap, the 14-bit count did 28 // Process ID. With the current trace event buffer cap, the 14-bit count did
29 // not appear to wrap during a trace. Note that it is not a big deal if 29 // not appear to wrap during a trace. Note that it is not a big deal if
30 // collisions occur, as this is only used for debugging and trace analysis. 30 // collisions occur, as this is only used for debugging and trace analysis.
31 return ((pid << 14) | (count & 0x3fff)) << 8; 31 return ((pid << 14) | (count & 0x3fff)) << 8;
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 namespace IPC { 36 namespace IPC {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 161
162 void Message::EnsureFileDescriptorSet() { 162 void Message::EnsureFileDescriptorSet() {
163 if (file_descriptor_set_.get() == NULL) 163 if (file_descriptor_set_.get() == NULL)
164 file_descriptor_set_ = new FileDescriptorSet; 164 file_descriptor_set_ = new FileDescriptorSet;
165 } 165 }
166 166
167 #endif 167 #endif
168 168
169 } // namespace IPC 169 } // namespace IPC
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