lkml.org 
[lkml]   [2012]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/3] trace-cmd: add checks for invalid pointers to fix segfaults
Date
Running 'trace-cmd report' after running latency tracers will cause a
segfault due to invalid pointers. Adding checks to ensure
pointers/lists are initialized before attempting to use them prevents
these segfaults.

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
---
trace-input.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/trace-input.c b/trace-input.c
index b6af1e6..5151c1e 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -695,7 +695,8 @@ static void __free_page(struct tracecmd_input *handle, struct page *page)

static void free_page(struct tracecmd_input *handle, int cpu)
{
- if (!handle->cpu_data[cpu].page)
+ if (!handle->cpu_data || cpu >= handle->cpus ||
+ !handle->cpu_data[cpu].page)
return;

__free_page(handle, handle->cpu_data[cpu].page);
@@ -746,8 +747,12 @@ void tracecmd_record_ref(struct record *record)

static void free_next(struct tracecmd_input *handle, int cpu)
{
- struct record *record = handle->cpu_data[cpu].next;
+ struct record *record;
+
+ if (!handle->cpu_data || cpu >= handle->cpus)
+ return;

+ record = handle->cpu_data[cpu].next;
if (!record)
return;

@@ -2337,7 +2342,8 @@ void tracecmd_close(struct tracecmd_input *handle)
/* The tracecmd_peek_data may have cached a record */
free_next(handle, cpu);
free_page(handle, cpu);
- if (!list_empty(&handle->cpu_data[cpu].pages))
+ if (handle->cpu_data &&
+ !list_empty(&handle->cpu_data[cpu].pages))
warning("pages still allocated on cpu %d%s",
cpu, show_records(&handle->cpu_data[cpu].pages));
}
--
1.7.5.4


\
 
 \ /
  Last update: 2012-04-05 21:23    [W:0.039 / U:1.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site