Skip to content

Commit 48ea8f5

Browse files
committed
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: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 23346f2 commit 48ea8f5

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎tools/perf/util/event.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ int event__synthesize_kernel_mmap(event__handler_t process,
288288
*/
289289
struct process_symbol_args args = { .name = symbol_name, };
290290

291-
mmap_name = machine__mmap_name(machine, name_buff);
291+
mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
292292
if (machine__is_host(machine)) {
293293
/*
294294
* kernel uses PERF_RECORD_MISC_USER for user space maps,
@@ -399,7 +399,7 @@ static int event__process_kernel_mmap(event_t *self,
399399
goto out_problem;
400400
}
401401

402-
machine__mmap_name(machine, kmmap_prefix);
402+
machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
403403
if (machine__is_host(machine))
404404
kernel_type = DSO_TYPE_KERNEL;
405405
else

‎tools/perf/util/map.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,14 @@ void machines__process(struct rb_root *self, machine__process_t process, void *d
629629
}
630630
}
631631

632-
char *machine__mmap_name(struct machine *self, char *buff)
632+
char *machine__mmap_name(struct machine *self, char *bf, size_t size)
633633
{
634634
if (machine__is_host(self))
635-
sprintf(buff, "[%s]", "kernel.kallsyms");
635+
snprintf(bf, size, "[%s]", "kernel.kallsyms");
636636
else if (machine__is_default_guest(self))
637-
sprintf(buff, "[%s]", "guest.kernel.kallsyms");
637+
snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
638638
else
639-
sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
639+
snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
640640

641-
return buff;
641+
return bf;
642642
}

‎tools/perf/util/map.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct machine *machines__add(struct rb_root *self, pid_t pid,
133133
struct machine *machines__find_host(struct rb_root *self);
134134
struct machine *machines__find(struct rb_root *self, pid_t pid);
135135
struct machine *machines__findnew(struct rb_root *self, pid_t pid);
136-
char *machine__mmap_name(struct machine *self, char *buff);
136+
char *machine__mmap_name(struct machine *self, char *bf, size_t size);
137137

138138
/*
139139
* Default guest kernel is defined by parameter --guestkallsyms

‎tools/perf/util/symbol.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
18561856
out_try_fixup:
18571857
if (err > 0) {
18581858
if (kallsyms_filename != NULL) {
1859-
machine__mmap_name(machine, path);
1859+
machine__mmap_name(machine, path, sizeof(path));
18601860
dso__set_long_name(self, strdup(path));
18611861
}
18621862
map__fixup_start(map);
@@ -1961,8 +1961,8 @@ struct dso *dso__new_kernel(const char *name)
19611961
static struct dso *dso__new_guest_kernel(struct machine *machine,
19621962
const char *name)
19631963
{
1964-
char buff[PATH_MAX];
1965-
struct dso *self = dso__new(name ?: machine__mmap_name(machine, buff));
1964+
char bf[PATH_MAX];
1965+
struct dso *self = dso__new(name ?: machine__mmap_name(machine, bf, sizeof(bf)));
19661966

19671967
if (self != NULL) {
19681968
dso__set_short_name(self, "[guest.kernel]");

0 commit comments

Comments
 (0)