Revision: 4953
Author: lukezarko
Date: Fri Jun 25 08:57:30 2010
Log: Avoid a potential null dereference wrt the CPU profiler.

GetActiveProfilerModules()/PauseProfiler()/ResumeProfiler() can be reached
from the API when the --prof runtime flag is not set, leading to null
dereferences. Verify that Logger::profiler_ is non-NULL before using it.

Review URL: http://codereview.chromium.org/2843023
http://code.google.com/p/v8/source/detail?r=4953

Modified:
 /branches/bleeding_edge/src/log.cc

=======================================
--- /branches/bleeding_edge/src/log.cc  Mon Jun  7 01:27:32 2010
+++ /branches/bleeding_edge/src/log.cc  Fri Jun 25 08:57:30 2010
@@ -309,10 +309,10 @@

 void Profiler::Run() {
   TickSample sample;
-  bool overflow = Logger::profiler_->Remove(&sample);
+  bool overflow = Remove(&sample);
   while (running_) {
     LOG(TickEvent(&sample, overflow));
-    overflow = Logger::profiler_->Remove(&sample);
+    overflow = Remove(&sample);
   }
 }

@@ -1150,7 +1150,7 @@

 int Logger::GetActiveProfilerModules() {
   int result = PROFILER_MODULE_NONE;
-  if (!profiler_->paused()) {
+  if (profiler_ != NULL && !profiler_->paused()) {
     result |= PROFILER_MODULE_CPU;
   }
   if (FLAG_log_gc) {
@@ -1162,7 +1162,7 @@

 void Logger::PauseProfiler(int flags, int tag) {
   if (!Log::IsEnabled()) return;
-  if (flags & PROFILER_MODULE_CPU) {
+  if (profiler_ != NULL && (flags & PROFILER_MODULE_CPU)) {
     // It is OK to have negative nesting.
     if (--cpu_profiler_nesting_ == 0) {
       profiler_->pause();
@@ -1193,7 +1193,7 @@
   if (tag != 0) {
     UncheckedIntEvent("open-tag", tag);
   }
-  if (flags & PROFILER_MODULE_CPU) {
+  if (profiler_ != NULL && (flags & PROFILER_MODULE_CPU)) {
     if (cpu_profiler_nesting_++ == 0) {
       ++logging_nesting_;
       if (FLAG_prof_lazy) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to