* [PATCH v2] perf tools: fix bug in usage of the basename() function
@ 2013-12-05 18:26 Stephane Eranian
2013-12-11 11:08 ` [tip:perf/core] perf symbols: Fix " tip-bot for Stephane Eranian
0 siblings, 1 reply; 2+ messages in thread
From: Stephane Eranian @ 2013-12-05 18:26 UTC (permalink / raw)
To: linux-kernel; +Cc: acme, peterz, jolsa, dsahern, bccheng
The basename() implementation varies a lot between systems.
The Linux man page says: "basename may modify the content of the path,
so it may be desirable to pass a copy when calling the function".
On some other systems, the returned address may come from an internal
buffer which can be reused in subsequent calls, thus the results should
also be copied.
The dso__set_basename() function was not doing this causing problems
on some systems with wrong library names being shown by perf report,
such as on Android systems.
This patch fixes the problem.
The patch is relative to tip.git.
In v2, we clean up the comments based on Ingo's feedback.
Reported-by: Ben Cheng <bccheng@google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
---
tools/perf/util/dso.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index af4c687c..976fac0 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -404,7 +404,34 @@ void dso__set_short_name(struct dso *dso, const char *name)
static void dso__set_basename(struct dso *dso)
{
- dso__set_short_name(dso, basename(dso->long_name));
+ char *lname, *base;
+
+ /*
+ * basename() may modify path buffer, so we must pass
+ * a copy.
+ */
+ lname = strdup(dso->long_name);
+ if (!lname)
+ return;
+
+ /*
+ * basename() may return a pointer to internal
+ * storage which is reused in subsequent calls
+ * so copy the result.
+ */
+ base = strdup(basename(lname));
+
+ free(lname);
+
+ if (!base)
+ return;
+
+ if (dso->sname_alloc)
+ free((char *)dso->short_name);
+ else
+ dso->sname_alloc = 1;
+
+ dso__set_short_name(dso, base);
}
int dso__name_len(const struct dso *dso)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:perf/core] perf symbols: Fix bug in usage of the basename() function
2013-12-05 18:26 [PATCH v2] perf tools: fix bug in usage of the basename() function Stephane Eranian
@ 2013-12-11 11:08 ` tip-bot for Stephane Eranian
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Stephane Eranian @ 2013-12-11 11:08 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, eranian, hpa, mingo, peterz, jolsa, bccheng,
dsahern, tglx
Commit-ID: ac5e7f84c0e050fe19146d9bf51f69890beabcef
Gitweb: http://git.kernel.org/tip/ac5e7f84c0e050fe19146d9bf51f69890beabcef
Author: Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 5 Dec 2013 19:26:42 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 10 Dec 2013 16:51:11 -0300
perf symbols: Fix bug in usage of the basename() function
The basename() implementation varies a lot between systems.
The Linux man page says: "basename may modify the content of the path,
so it may be desirable to pass a copy when calling the function".
On some other systems, the returned address may come from an internal
buffer which can be reused in subsequent calls, thus the results should
also be copied.
The dso__set_basename() function was not doing this causing problems
on some systems with wrong library names being shown by perf report,
such as on Android systems.
This patch fixes the problem.
The patch is relative to tip.git.
In v2, we clean up the comments based on Ingo's feedback.
Reported-by: Ben Cheng <bccheng@google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Ben Cheng <bccheng@google.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20131205182642.GA14614@quad
[ v3: Fixed up wrt allocated flag now being set in dso__set_short_name ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/dso.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 582b5d3..436922f 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -413,7 +413,28 @@ void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
static void dso__set_basename(struct dso *dso)
{
- dso__set_short_name(dso, basename((char *)dso->long_name), false);
+ /*
+ * basename() may modify path buffer, so we must pass
+ * a copy.
+ */
+ char *base, *lname = strdup(dso->long_name);
+
+ if (!lname)
+ return;
+
+ /*
+ * basename() may return a pointer to internal
+ * storage which is reused in subsequent calls
+ * so copy the result.
+ */
+ base = strdup(basename(lname));
+
+ free(lname);
+
+ if (!base)
+ return;
+
+ dso__set_short_name(dso, base, true);
}
int dso__name_len(const struct dso *dso)
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-11 11:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05 18:26 [PATCH v2] perf tools: fix bug in usage of the basename() function Stephane Eranian
2013-12-11 11:08 ` [tip:perf/core] perf symbols: Fix " tip-bot for Stephane Eranian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox