perf machine: Pass buffer size to machine__mmap_name

Don't blindly assume that the size of the buffer is enough, use
snprintf.

Cc: Avi Kivity <avi@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Zhang, Yanmin <yanmin_zhang@linux.intel.com>
LKML-Reference: <new-submission>
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 23346f21
...@@ -288,7 +288,7 @@ int event__synthesize_kernel_mmap(event__handler_t process, ...@@ -288,7 +288,7 @@ int event__synthesize_kernel_mmap(event__handler_t process,
*/ */
struct process_symbol_args args = { .name = symbol_name, }; struct process_symbol_args args = { .name = symbol_name, };
mmap_name = machine__mmap_name(machine, name_buff); mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
if (machine__is_host(machine)) { if (machine__is_host(machine)) {
/* /*
* kernel uses PERF_RECORD_MISC_USER for user space maps, * kernel uses PERF_RECORD_MISC_USER for user space maps,
...@@ -399,7 +399,7 @@ static int event__process_kernel_mmap(event_t *self, ...@@ -399,7 +399,7 @@ static int event__process_kernel_mmap(event_t *self,
goto out_problem; goto out_problem;
} }
machine__mmap_name(machine, kmmap_prefix); machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
if (machine__is_host(machine)) if (machine__is_host(machine))
kernel_type = DSO_TYPE_KERNEL; kernel_type = DSO_TYPE_KERNEL;
else else
......
...@@ -629,14 +629,14 @@ void machines__process(struct rb_root *self, machine__process_t process, void *d ...@@ -629,14 +629,14 @@ void machines__process(struct rb_root *self, machine__process_t process, void *d
} }
} }
char *machine__mmap_name(struct machine *self, char *buff) char *machine__mmap_name(struct machine *self, char *bf, size_t size)
{ {
if (machine__is_host(self)) if (machine__is_host(self))
sprintf(buff, "[%s]", "kernel.kallsyms"); snprintf(bf, size, "[%s]", "kernel.kallsyms");
else if (machine__is_default_guest(self)) else if (machine__is_default_guest(self))
sprintf(buff, "[%s]", "guest.kernel.kallsyms"); snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
else else
sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", self->pid); snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
return buff; return bf;
} }
...@@ -133,7 +133,7 @@ struct machine *machines__add(struct rb_root *self, pid_t pid, ...@@ -133,7 +133,7 @@ struct machine *machines__add(struct rb_root *self, pid_t pid,
struct machine *machines__find_host(struct rb_root *self); struct machine *machines__find_host(struct rb_root *self);
struct machine *machines__find(struct rb_root *self, pid_t pid); struct machine *machines__find(struct rb_root *self, pid_t pid);
struct machine *machines__findnew(struct rb_root *self, pid_t pid); struct machine *machines__findnew(struct rb_root *self, pid_t pid);
char *machine__mmap_name(struct machine *self, char *buff); char *machine__mmap_name(struct machine *self, char *bf, size_t size);
/* /*
* Default guest kernel is defined by parameter --guestkallsyms * Default guest kernel is defined by parameter --guestkallsyms
......
...@@ -1856,7 +1856,7 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map, ...@@ -1856,7 +1856,7 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
out_try_fixup: out_try_fixup:
if (err > 0) { if (err > 0) {
if (kallsyms_filename != NULL) { if (kallsyms_filename != NULL) {
machine__mmap_name(machine, path); machine__mmap_name(machine, path, sizeof(path));
dso__set_long_name(self, strdup(path)); dso__set_long_name(self, strdup(path));
} }
map__fixup_start(map); map__fixup_start(map);
...@@ -1961,8 +1961,8 @@ struct dso *dso__new_kernel(const char *name) ...@@ -1961,8 +1961,8 @@ struct dso *dso__new_kernel(const char *name)
static struct dso *dso__new_guest_kernel(struct machine *machine, static struct dso *dso__new_guest_kernel(struct machine *machine,
const char *name) const char *name)
{ {
char buff[PATH_MAX]; char bf[PATH_MAX];
struct dso *self = dso__new(name ?: machine__mmap_name(machine, buff)); struct dso *self = dso__new(name ?: machine__mmap_name(machine, bf, sizeof(bf)));
if (self != NULL) { if (self != NULL) {
dso__set_short_name(self, "[guest.kernel]"); dso__set_short_name(self, "[guest.kernel]");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册