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

Side by Side Diff: base/trace_event/trace_event_android.cc

Issue 1490763006: Fix buffer overflow in trace_event_android.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « base/trace_event/trace_event.gypi ('k') | base/trace_event/trace_event_android_unittest.cc » ('j') | 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 "base/trace_event/trace_event_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 15
16 namespace base { 16 namespace base {
17 namespace trace_event { 17 namespace trace_event {
18 18
19 namespace { 19 namespace {
20 20
21 int g_atrace_fd = -1; 21 int g_atrace_fd = -1;
22 const char kATraceMarkerFile[] = "/sys/kernel/debug/tracing/trace_marker"; 22 const char kATraceMarkerFile[] = "/sys/kernel/debug/tracing/trace_marker";
23 23
24 void WriteToATrace(int fd, const char* buffer, size_t size) { 24 void WriteToATrace(int fd, const char* buffer, size_t size) {
25 size_t total_written = 0; 25 size_t total_written = 0;
26 while (total_written < size) { 26 while (total_written < size) {
27 ssize_t written = HANDLE_EINTR(write( 27 ssize_t written = HANDLE_EINTR(write(
28 fd, buffer + size, size - total_written)); 28 fd, buffer + total_written, size - total_written));
29 if (written <= 0) 29 if (written <= 0)
30 break; 30 break;
31 total_written += written; 31 total_written += written;
32 } 32 }
33 if (total_written < size) { 33 if (total_written < size) {
34 PLOG(WARNING) << "Failed to write buffer '" << std::string(buffer, size) 34 PLOG(WARNING) << "Failed to write buffer '" << std::string(buffer, size)
35 << "' to " << kATraceMarkerFile; 35 << "' to " << kATraceMarkerFile;
36 } 36 }
37 } 37 }
38 38
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // trace buffer. 203 // trace buffer.
204 double now_in_seconds = (TimeTicks::Now() - TimeTicks()).InSecondsF(); 204 double now_in_seconds = (TimeTicks::Now() - TimeTicks()).InSecondsF();
205 std::string marker = StringPrintf( 205 std::string marker = StringPrintf(
206 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds); 206 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
207 WriteToATrace(atrace_fd, marker.c_str(), marker.size()); 207 WriteToATrace(atrace_fd, marker.c_str(), marker.size());
208 close(atrace_fd); 208 close(atrace_fd);
209 } 209 }
210 210
211 } // namespace trace_event 211 } // namespace trace_event
212 } // namespace base 212 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event.gypi ('k') | base/trace_event/trace_event_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698