From: Mark Asselstine <mark.asselstine@windriver.com>
To: <rostedt@goodmis.org>
Cc: <linux-kernel@vger.kernel.org>, <mark.asselstine@windriver.com>
Subject: [PATCH 1/3] trace-cmd: add checks for invalid pointers to fix segfaults
Date: Thu, 5 Apr 2012 15:19:44 -0400 [thread overview]
Message-ID: <1333653586-3379-2-git-send-email-mark.asselstine@windriver.com> (raw)
In-Reply-To: <1333653586-3379-1-git-send-email-mark.asselstine@windriver.com>
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
next prev parent reply other threads:[~2012-04-05 19:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-05 19:19 [PATCH 0/3] trace-cmd fixes for latency tracing record and report Mark Asselstine
2012-04-05 19:19 ` Mark Asselstine [this message]
2012-04-05 19:19 ` [PATCH 2/3] trace-cmd: don't call stop_threads() if doing latency tracing Mark Asselstine
2012-04-05 19:19 ` [PATCH 3/3] trace-cmd: setting plugin to 'nop' clears data before its recorded Mark Asselstine
2012-04-05 21:37 ` Steven Rostedt
2012-04-06 12:06 ` Mark Asselstine
2012-04-06 12:24 ` Steven Rostedt
2012-04-08 15:38 ` [PATCH v2 3/3] trace-cmd: setting plugin to 'nop' clears data before it's recorded Mark Asselstine
2012-05-23 9:33 ` Steven Rostedt
2012-05-23 13:26 ` Mark Asselstine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1333653586-3379-2-git-send-email-mark.asselstine@windriver.com \
--to=mark.asselstine@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®