mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Robert Richter <robert.richter@amd.com>
Subject: [PATCH v2 2/7] perf tools: Fix out-of-bound access to struct perf_session
Date: Wed, 7 Dec 2011 10:02:52 +0100	[thread overview]
Message-ID: <1323248577-11268-3-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1323248577-11268-1-git-send-email-robert.richter@amd.com>

If filename is NULL there is an out-of-bound access to struct
perf_session if it would be used with perf_session__open(). Shouldn't
actually happen in current implementation as filename is always
!NULL. Fixing this by always null-terminating filename.

Signed-off-by: Robert Richter <robert.richter@amd.com>
---
 tools/perf/util/session.c |    2 +-
 tools/perf/util/session.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d9318d8..ea17dfb 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -107,7 +107,7 @@ struct perf_session *perf_session__new(const char *filename, int mode,
 				       bool force, bool repipe,
 				       struct perf_tool *tool)
 {
-	size_t len = filename ? strlen(filename) + 1 : 0;
+	size_t len = filename ? strlen(filename) : 0;
 	struct perf_session *self = zalloc(sizeof(*self) + len);
 
 	if (self == NULL)
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 30e9c6b6..7d3be1b 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -50,7 +50,7 @@ struct perf_session {
 	int			cwdlen;
 	char			*cwd;
 	struct ordered_samples	ordered_samples;
-	char			filename[0];
+	char			filename[1];
 };
 
 struct perf_tool;
-- 
1.7.7



  parent reply	other threads:[~2011-12-07  9:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07  9:02 [PATCH v2 0/7] perf tools: cleanups, fixes, updates Robert Richter
2011-12-07  9:02 ` [PATCH v2 1/7] perf tools: Continue processing header on unknown features Robert Richter
2011-12-29 20:52   ` [tip:perf/core] " tip-bot for Robert Richter
2011-12-07  9:02 ` Robert Richter [this message]
2011-12-29 20:53   ` [tip:perf/core] perf tools: Fix out-of-bound access to struct perf_session tip-bot for Robert Richter
2011-12-07  9:02 ` [PATCH v2 3/7] perf tool: Moving code in some files Robert Richter
2011-12-29 20:53   ` [tip:perf/core] perf tools: " tip-bot for Robert Richter
2011-12-07  9:02 ` [PATCH v2 4/7] perf report: Accept fifos as input file Robert Richter
2011-12-29 20:54   ` [tip:perf/core] " tip-bot for Robert Richter
2011-12-07  9:02 ` [PATCH v2 5/7] perf tool: Unify handling of features when writing feature section Robert Richter
2011-12-29 20:55   ` [tip:perf/core] perf tools: " tip-bot for Robert Richter
2011-12-07  9:02 ` [PATCH v2 6/7] perf tools: Improve macros for struct feature_ops Robert Richter
2011-12-29 20:51   ` [tip:perf/core] " tip-bot for Robert Richter
2011-12-07  9:02 ` [PATCH v2 7/7] perf tools: Use for_each_set_bit() to iterate over feature flags Robert Richter
2011-12-29 20:56   ` [tip:perf/core] " tip-bot for Robert Richter

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=1323248577-11268-3-git-send-email-robert.richter@amd.com \
    --to=robert.richter@amd.com \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.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

Powered by JetHome